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
相关推荐
夏季疯2 小时前
读论文:STARS 是什么结构?一个统一的歌声自动标注框架
python
鱼儿也有烦恼2 小时前
快速学完 LeetCode top 1~50
leetcode·algorithm
光测实验室2 小时前
3种Python降噪算法实测:我把处理速度提升了20倍
python
AOwhisky2 小时前
Python 学习笔记(第三期)——流程控制核心知识点自测与详解
开发语言·笔记·python·学习·云原生·运维开发·流程控制
爱吃提升3 小时前
Python桌面自动化PyAutoGUI完整实战教程:模拟鼠标键盘、窗口操作、图形识别自动化
python·自动化·计算机外设
花花无缺3 小时前
Windows 定时执行 Python 脚本方案
python·操作系统·命令行
流云鹤5 小时前
1. 配置环境、创建导航栏
python·django
三亚兴嘉装饰5 小时前
准备在三亚装房子找哪家装修
python
Mx_coder5 小时前
8年Java开发者AI转型第二周:RAG系统深入 + 向量数据库实战(Day 8-10)
python
ximen502_6 小时前
Python 语言知识总结
开发语言·python