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
相关推荐
Ethan-D20 小时前
#每日一题19 回溯 + 全排列思想
java·开发语言·python·算法·leetcode
橘颂TA21 小时前
【剑斩OFFER】算法的暴力美学——LeetCode 733 题:图像渲染
算法·leetcode·职场和发展
weixin_4469340321 小时前
统计学中“in sample test”与“out of sample”有何区别?
人工智能·python·深度学习·机器学习·计算机视觉
weixin_462446231 天前
使用 Python 测试 Mermaid 与 Graphviz 图表生成(支持中文)
python·mermaid·graphviz
JOBkiller1231 天前
钢绞线缺陷检测与识别_Cascade-Mask-RCNN_RegNetX模型训练与应用实战
python
nvd111 天前
深入 ReAct Agent 的灵魂拷问:从幻觉到精准执行的调试实录
python·langchain
Ulyanov1 天前
战场地形生成与多源数据集成
开发语言·python·算法·tkinter·pyside·pyvista·gui开发
love530love1 天前
告别环境崩溃:ONNX 与 Protobuf 版本兼容性指南
人工智能·windows·python·onnx·stablediffusion·comfyui·protobuf
FMRbpm1 天前
树的练习6--------938.二叉搜索树的范围和
数据结构·c++·算法·leetcode·职场和发展·新手入门
ID_180079054731 天前
日本乐天商品详情API接口的请求构造与参数说明
开发语言·python·pandas