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
相关推荐
XWalnut12 分钟前
LeetCode刷题 day37
java·数据结构·算法·leetcode
万山寒13 分钟前
python依赖包导出离线安装到没有外网的服务器
服务器·开发语言·python
程序员雷欧39 分钟前
LongAdder
开发语言·python
月光船幽幽1 小时前
分层阈值规避归藏协议过度重置
人工智能·python
SMF19191 小时前
【Linux】完美解决缩略图工具gm调用java.io.FileNotFoundException: gm问题
java·开发语言·python
㳺三才人子1 小时前
初探 Data Analysis - Matplotlib
python·plotly·pandas·matplotlib
Python私教1 小时前
0、null、未采集:AI Agent 反馈系统最容易踩的语义坑
人工智能·python
北斗落凡尘1 小时前
LangGraph 入门实战(5)
python·langchain
Python私教1 小时前
请求超时不等于失败:把写操作恢复设计成事实回读
后端·python
且听风吟02202 小时前
7.包管理工具
python