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
相关推荐
Wonderful U3 分钟前
Python+Django实战|在线音乐分享平台:音乐上传、歌手专辑管理、在线播放、自定义歌单、收藏点赞、评论互动
开发语言·python·django
lzjava20247 分钟前
Python的数据结构,推导式、迭代器和生成器
数据结构·windows·python
北极星日淘16 分钟前
煤炉自动代拍功能开发 | Python 异步任务实现批量下单
开发语言·python·自动化
光之后裔22 分钟前
用自定义数据集微调PP-OCRv5文本检测、识别模型
python·机器学习·ocr
2301_7644413343 分钟前
基于AI的本地文件归档智能管理工具梳理
人工智能·python·算法·目标检测·交互
二十七剑1 小时前
LangGraph 源码深度解析:Node 节点 Protocol 与 StateNodeSpec 核心机制
开发语言·python
AC赳赳老秦1 小时前
OpenClaw + 云数据库运维:自动备份、扩容、迁移 RDS/MySQL 云数据库
运维·开发语言·数据库·人工智能·python·mysql·openclaw
Tbisnic1 小时前
AI大模型学习第十二天:Coze工作流与智能体开发
人工智能·python·ai·大模型·智能体·coze
冷小鱼1 小时前
高级研发编码习惯:从规范到艺术,再到AI+时代的人机协同
java·开发语言·python·编码习惯