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
相关推荐
寻星探路5 分钟前
【算法专题】哈希表:从“两数之和”到“最长连续序列”的深度解析
java·数据结构·人工智能·python·算法·ai·散列表
@zulnger7 分钟前
python 学习笔记(闭包)
笔记·python·学习
SHolmes18549 分钟前
Python all函数 判断是否同时满足多个条件
java·服务器·python
inksci9 分钟前
Python 中使用 SQL 连接池
服务器·数据库·python
子午13 分钟前
【2026原创】中草药识别系统实现~Python+深度学习+模型训练+人工智能
人工智能·python·深度学习
洛克大航海13 分钟前
Python 在系统 Windows 和 Ubuntu 中创建虚拟环境
windows·python·ubuntu·虚拟环境
ZEERO~15 分钟前
@dataclass的作用
开发语言·windows·python
独自破碎E25 分钟前
【队列】求二叉树的层序遍历
leetcode
几道之旅25 分钟前
pytdx能否下载期货数据呢?
python
vyuvyucd29 分钟前
MPPI算法实战:机器人避障与仿真
python