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
相关推荐
千里码aicood4 分钟前
基于Python的电商数据采集系统(大数据+爬虫)
开发语言·python
战略性的菠萝25 分钟前
研究生基础-Python快速入门(终)——面向对象
python
陈皮波比茶31 分钟前
Python项目实战-网络机器人(爬虫)
开发语言·网络·爬虫·python·机器人
winfredzhang1 小时前
从零构建家庭照片管理系统:Django 模块化单体实战,以及我踩到的 4 个真实坑
python·postgresql·django·sqlite·bootsrap
jyOverQ1 小时前
LangGraph 流式执行详解:stream、astream 与 stream_mode 怎么选?
python·langchain
闲猫2 小时前
LangGraph / Capabilities / Stores
python·agent·langgraph
pjj198542 小时前
机器学习-NumPy2
人工智能·python·机器学习
OPEN-F2 小时前
Python进阶教程:单元测试与代码质量
开发语言·python·单元测试
Logintern092 小时前
装饰器和洋葱模式的区分
开发语言·python·架构
呆呆敲代码的小Y3 小时前
10 分钟搞懂 cua:开源 AI 操作电脑基础设施,附 Python 沙箱与 Agent 上手代码
人工智能·python·开源·ai agent·awesome·llm应用·cua