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
相关推荐
夏鹏今天学习了吗35 分钟前
【LeetCode热题100(56/100)】组合总和
算法·leetcode·职场和发展
ZPC82101 小时前
opencv 获取图像中物体的坐标值
人工智能·python·算法·机器人
测试19981 小时前
如何写出一个完整的测试用例?
自动化测试·软件测试·python·测试工具·职场和发展·测试用例·接口测试
微笑尅乐1 小时前
三种方法解开——力扣3370.仅含置位位的最小整数
python·算法·leetcode
多恩Stone2 小时前
【3DV 进阶-5】3D生成中 Inductive Bias (归纳偏置)的技术路线图
人工智能·python·算法·3d·aigc
闲人编程2 小时前
使用Python进行量化交易入门
开发语言·python·统计分析·lambda·量化·codecapsule
长颈鹿仙女4 小时前
发送 Prompt 指令:判断用户评价是好评还是差评
python·大模型
小兔崽子去哪了4 小时前
PyMySQL 笔记
python
景彡先生4 小时前
Python NumPy广播机制详解:从原理到实战,数组运算的“隐形翅膀”
开发语言·python·numpy
咕白m6254 小时前
Python 查找高亮 Excel 指定数据
python