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
相关推荐
金融小师妹9 小时前
多因子智能推演:油价回落6%与黄金震荡上行的关联解析——AI预测框架
大数据·python·深度学习
BUG研究员_12 小时前
Runnable与LCEL
开发语言·人工智能·python
老马聊技术12 小时前
Pytorch深度学习环境配置与测试
人工智能·pytorch·python
Python私教13 小时前
AI Agent 上生产要不要开写权限?我把执行链拆成 4 道闸门
人工智能·后端·python
天才测试猿13 小时前
软件测试知识总结(基础篇)
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
崔子末13 小时前
某影视库剧集列表以及查询接口逆向
爬虫·python
gogogo出发喽13 小时前
v3 admin
python
问商十三载14 小时前
RAG 检索效果差怎么排查?2026 五层诊断法完整指南
开发语言·人工智能·windows·python·算法
weixin_BYSJ198715 小时前
springboot酒店管理系统--附源码27436
java·spring boot·python·随机森林·贪心算法·eclipse·django