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
相关推荐
_爱明几秒前
查看模型参数量
人工智能·pytorch·python
m0_635647483 分钟前
pyqt5打包报错:qt.qpa.plugin: Could not load the Qt platform plugin “windows“
开发语言·windows·python·qt·pyqt
人工干智能7 分钟前
大模型应用中,创建OpenAI客户端的三种方式
python·llm
智算菩萨12 分钟前
【Python基础】AI的“重复学习”:循环语句(for, while)的奥秘
人工智能·python·学习
代码方舟14 分钟前
不仅是评分:利用 Python 解析天远借贷行为验证API 的 T0-T11 借贷时间轴数据
大数据·开发语言·python
想学后端的前端工程师15 分钟前
【Java JVM虚拟机深度解析:从原理到调优】
java·jvm·python
幽影相随28 分钟前
TensorBoard 快速使用指南
pytorch·python·tensorboard
其美杰布-富贵-李33 分钟前
TensorBoard 与 WandB 在 PyTorch Lightning 中的完整指南
人工智能·pytorch·python·监控·调优
Python永远的神34 分钟前
告别循环:Python 列表推导式,让你的代码飞起来!
python
Vic1010138 分钟前
Spring AOP 高级陷阱:为什么 @Before 修改参数是“伪修改“?
java·python·spring