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
相关推荐
Hello_wshuo2 小时前
锅炉温控系统优化
linux·python·物联网
weixin_470740362 小时前
python生成环境部署
开发语言·python
piaopiaolanghua2 小时前
Python中的SGP4轨道预报库
python·sgp4
Eiceblue2 小时前
Python 实现 CSV 转 TXT 格式 (单文件 + 批量处理)
开发语言·python·visual studio code
Iridescent11212 小时前
Iridescent:Day49
python
曲幽3 小时前
从安装到上线:一份 Nginx 实战指南,让你的 Web 应用稳建安全
python·nginx·flask·fastapi·web·gunicorn·uvicorn
vibag3 小时前
LangSmith监控
人工智能·python·语言模型·langchain·大模型
橘颂TA3 小时前
【剑斩OFFER】算法的暴力美学——两数之和
数据结构·算法·leetcode·力扣·结构与算法
云里雾里!3 小时前
力扣 268. 缺失数字 ✅ 【位运算(异或)最优解法】深度解析
算法·leetcode
YJlio3 小时前
PsPing 学习笔记(14.7):一条龙网络体检脚本——连通性、延迟、带宽全都要
开发语言·网络·笔记·python·学习·pdf·php