Python | Leetcode Python题解之第125题验证回文串

题目:

题解:

python 复制代码
class Solution:
    def isPalindrome(self, s: str) -> bool:
        n = len(s)
        left, right = 0, n - 1
        
        while left < right:
            while left < right and not s[left].isalnum():
                left += 1
            while left < right and not s[right].isalnum():
                right -= 1
            if left < right:
                if s[left].lower() != s[right].lower():
                    return False
                left, right = left + 1, right - 1

        return True
相关推荐
2301_764441337 小时前
三维建筑非法入侵情景推演
python·学习·算法
爱写代码的小朋友8 小时前
21天学通Python全栈开发实战指南
开发语言·python
java1234_小锋8 小时前
基于Python深度学习的车辆车牌识别系统(PyTorch2卷积神经网络CNN+OpenCV4实现)视频教程 - 裁剪和矫正车牌
python·深度学习·cnn·车牌识别
软件测试曦曦8 小时前
使用Python接口自动化测试post请求和get请求,获取请求返回值
开发语言·自动化测试·软件测试·python·功能测试·程序人生·职场和发展
陈奕昆8 小时前
n8n实战营Day2:复杂逻辑控制·HTTP请求+条件分支节点实操
网络·人工智能·python·网络协议·n8n
Aerelin8 小时前
爬虫playwright中的等待机制
前端·爬虫·python
卡比巴拉—林8 小时前
Python print()函数详讲
开发语言·python
奶思图米球8 小时前
Python多环境管理
开发语言·python
Aerelin8 小时前
iframe讲解(爬虫playwright的特殊应用)
前端·爬虫·python·html
CoderYanger8 小时前
递归、搜索与回溯-综合练习:19.目标和
java·算法·leetcode·1024程序员节