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
相关推荐
kong79069282 分钟前
Python核心语法-Python自定义模块、Python包
开发语言·python·python核心语法
OLOLOadsd12310 分钟前
基于Mask-RCNN和RegNetX的茎蛀虫检测识别系统详解
python
半路_出家ren22 分钟前
1.古典密码概述
python·网络安全·密码学·古典密码·加密方式
夏鹏今天学习了吗30 分钟前
【LeetCode热题100(90/100)】编辑距离
算法·leetcode·职场和发展
CJenny1 小时前
Claude Code常用操作和使用方法
人工智能·python
事橙19991 小时前
KITTI数据集国内下载链接
人工智能·python·yolo
HarmonLTS2 小时前
Python人工智能深度开发:技术体系、核心实践与工程化落地
开发语言·人工智能·python·算法
weixin_462446232 小时前
Python 解析 Excel 图表(Chart)信息实战:从 xlsx 中提取标题、字体和数据
python·数据分析·excel·报表自动化
一分之二~2 小时前
二叉树--层序遍历(迭代和递归)
数据结构·c++·算法·leetcode
weixin_462446232 小时前
使用 Python 脚本自动化管理 Docker 容器:启动、修改密码、删除及系统资源监控
python·docker·自动化·系统监控