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
相关推荐
淼澄研学3 分钟前
PyTorch核心实操:从张量计算到混合精度训练的5个关键步骤
人工智能·pytorch·python
梦想三三8 分钟前
Qwen Function Calling实战:重构电商客服AI Agent
人工智能·python·langchain·大模型·rag
05664611 分钟前
agent学习Day23——文件上传与 Embedding 语义检索
python·学习·embedding
leisoo809712 分钟前
筹码分布数据分析实战:用Python构建主力建仓成本分析系统
python·数据挖掘·数据分析
淼澄研学15 分钟前
PyTorch 2.0 核心机制解析与5个实操方法
人工智能·pytorch·python
rogabet-note38 分钟前
cef3和tkinter网页浏览器
python
半兽先生38 分钟前
MinerU + LibreOffice 混合架构:搞定 .doc/.ppt 旧格式文档解析与切片
人工智能·python·机器学习·ai·架构
小趴蔡ha43 分钟前
03 NumPy 入门:机器学习中的数组和矩阵
python·线性代数·机器学习·numpy
m0_519196401 小时前
【设计模式】java的习题
开发语言·python
pt10431 小时前
网络自动化Python课程:Git版本控制基础入门与实验演示
网络·python·自动化