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
相关推荐
奇牙7 小时前
DeepSeek V4 Agent 开发实战:用 deepseek-v4-pro 搭建多步骤工作流(2026 完整代码)
python
斯维赤7 小时前
Python学习超简单第八弹:连接Mysql数据库
数据库·python·学习
qq_654366987 小时前
如何排查Oracle客户端连接慢_DNS解析超时与sqlnet配置优化
jvm·数据库·python
迷途酱8 小时前
手写一个 AI Agent:从 Function Calling 到自动化任务链
python
Gerardisite8 小时前
企微机器人开发指南
java·python·机器人·自动化·企业微信
城管不管9 小时前
嵌入模型Embedding Model
java·开发语言·python·embedding·嵌入模型
Architect_Lee9 小时前
python3.14.4环境搭建
python
适应规律9 小时前
pointnet 实战
python
慕涯AI9 小时前
Agent 30 课程开发指南 - 第28课
人工智能·python
迷途酱9 小时前
RAG 从零到一:用 Python 给大模型接上你的私有知识库
python