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
相关推荐
垆边人似月.1 小时前
Python中如何使用get函数实现频次查询
服务器·前端·python
AI 编程助手GPT1 小时前
GPT 脚本别只发一个文件:用 uv 把依赖和锁一起交付
人工智能·python·gpt·uv·依赖管理
Patrick在香港2 小时前
第 16,216 次连接之后,它不干了
python·网络编程·socket·tcp·连接池
我命由我123452 小时前
Python 开发 - Python 虚拟环境
运维·开发语言·后端·python·http·https·java-ee
云和数据.ChenGuang2 小时前
LLM大模型对接本地Ollama部署模型
开发语言·人工智能·python·langchain
文丑颜不良啊2 小时前
LeetCode276~300题目解析
java·leetcode
云和数据.ChenGuang3 小时前
光哥说Python 循环导入(Circular Import)深度解析:成因、排查与解决方案
开发语言·前端·人工智能·python·langchain
TomEval3 小时前
【测AI】第16篇:模型公平性与可解释性测试 — AI 的偏见与黑箱
人工智能·python·功能测试·ai·测试用例
田里的水稻3 小时前
FA_CNN卷积神经网络四---线性层及其拉平PyTorch
人工智能·pytorch·python·深度学习·神经网络·cnn
钱栈up3 小时前
GitHub热榜上手|Claude插件:4.3万星官方目录
python·开源·github