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
相关推荐
love530love11 分钟前
Windows 11 下 Z-Image-Turbo 完整部署与 Flash Attention 2.8.3 本地编译复盘
人工智能·windows·python·aigc·flash-attn·z-image·cuda加速
YGGP22 分钟前
【Golang】LeetCode 32. 最长有效括号
算法·leetcode
MediaTea44 分钟前
Python:模块 __dict__ 详解
开发语言·前端·数据库·python
jarreyer1 小时前
python,numpy,pandas和matplotlib版本对应关系
python·numpy·pandas
代码or搬砖1 小时前
HashMap源码
开发语言·python·哈希算法
顽强卖力3 小时前
第二章:什么是数据分析师?
笔记·python·职场和发展·学习方法
站大爷IP3 小时前
Python实现Excel数据自动化处理:从繁琐操作到智能流程的蜕变
python
YGGP3 小时前
【Golang】LeetCode 5. 最长回文子串
算法·leetcode
BBB努力学习程序设计3 小时前
Python 进阶知识点精讲:上下文管理器(Context Manager)的原理与实战
python·pycharm
清水白石0083 小时前
《深入 super() 的世界:MRO 与 C3 线性化算法的全景解析与实战指南》
python