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
相关推荐
源代码•宸11 分钟前
Leetcode—746. 使用最小花费爬楼梯【简单】
后端·算法·leetcode·职场和发展·golang·记忆化搜索·动规
南 阳11 分钟前
Python从入门到精通day16
开发语言·python·算法
沉默-_-15 分钟前
力扣hot100-子串(C++)
c++·学习·算法·leetcode·子串
MasonYyp19 分钟前
Agno中使用MCP
python
aiguangyuan19 分钟前
从零实现循环神经网络:中文情感分析的完整实践指南
人工智能·python·nlp
POLITE335 分钟前
Leetcode 437. 路径总和 III (Day 16)JavaScript
javascript·算法·leetcode
喵手35 分钟前
Python爬虫零基础入门【第九章:实战项目教学·第1节】通用新闻采集器:从零打造可复用的静态站模板!
爬虫·python·爬虫实战·python爬虫工程化实战·零基础python爬虫教学·新闻采集器·静态站模版
摸鱼仙人~1 小时前
从 Gunicorn 到 FastAPI:Python Web 生产环境架构演进与实战指南
python·fastapi·gunicorn
毕设源码-朱学姐1 小时前
【开题答辩全过程】以 基于Django框架中山社区社会补助系统为例,包含答辩的问题和答案
后端·python·django
醉舞经阁半卷书11 小时前
Matplotlib从入门到精通
python·数据分析·matplotlib