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
相关推荐
用户8356290780517 分钟前
用 Python 轻松在 Excel 工作表中应用条件格式
后端·python
red1giant_star11 分钟前
Python根据文件后缀统计文件大小、找出文件位置(仿Everything)
后端·python
雷欧力23 分钟前
如何使用 Claude API?3 种接入方案实测,附完整代码(2026)
python·claude
神仙别闹28 分钟前
基于 Python 实现 BERT 的情感分析模型
开发语言·python·bert
NQBJT35 分钟前
VS Code配置Python人工智能开发环境
开发语言·人工智能·vscode·python
浮游本尊36 分钟前
一文讲透巡检链路:采集程序 → 上传数据包 → 后端解析入库 → 分析出报告
python
a1117761 小时前
MonoGS 在 Jetson Orin Nano 上的部署与性能测试
python·开源·torch·cv
偶尔微微一笑1 小时前
智能体四大核心模块揭秘
python
2301_815901971 小时前
SQL如何将多行记录聚合成逗号分隔字符串_GROUP_CONCAT技巧
jvm·数据库·python
西索斯1 小时前
Claude API 报 529 Overloaded 怎么办?3 种方案实测,最后一种最省心
python·claude