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
相关推荐
长行22 分钟前
Python|Windows 安装 DeepSpeed 安装方法及报错 Unable to pre-compile async_io 处理
windows·python·deepspeed
百锦再22 分钟前
python之路并不一马平川:带你踩坑Pandas
开发语言·python·pandas·pip·requests·tools·mircro
Python之栈22 分钟前
5款拖拽式Python GUI生成器助你快速打造炫酷界面
python
灏瀚星空23 分钟前
基于 Python 与 GitHub,打造个人专属本地化思维导图工具全流程方案(上)
开发语言·人工智能·经验分享·笔记·python·个人开发·visual studio
用什么都重名23 分钟前
「实战指南」使用 Python 调用大模型(LLM)
python·大模型·llm·api调用
是Dream呀23 分钟前
Python从0到100(一百):基于Transformer的时序数据建模与实现详解
开发语言·python·transformer
资源存储库24 分钟前
【笔记】如何修改一个conda环境的python版本?
笔记·python·conda
xcLeigh24 分钟前
AI的提示词专栏:Prompt 与 Python Pandas 的结合使用指南
人工智能·python·ai·prompt·提示词
草莓熊Lotso25 分钟前
Python 入门超详细指南:环境搭建 + 核心优势 + 应用场景(零基础友好)
运维·开发语言·人工智能·python·深度学习·学习·pycharm
正在走向自律25 分钟前
ksycopg2实战:Python连接KingbaseES数据库的完整指南
数据库·python·国产数据库·kingbase·kingbasees·数据库平替用金仓·ksycopg2