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
相关推荐
EnCi Zheng几秒前
P1B-Python环境配置基础完全指南-Windows系统安装与验证
开发语言·windows·python
一叶落4384 分钟前
LeetCode 151. 反转字符串中的单词(C语言)【双指针 + 字符串处理】
c语言·数据结构·算法·leetcode
小小怪7505 分钟前
实战:用Python开发一个简单的区块链
jvm·数据库·python
junnhwan6 分钟前
LeetCode Hot 100——栈
java·数据结构·算法·leetcode·hot 100
云和数据.ChenGuang8 分钟前
数据分析中的dataframe详解
python·数据挖掘·数据分析·django·pygame
echome8889 分钟前
Python 装饰器详解:从入门到实战
开发语言·python
圣保罗的大教堂10 分钟前
leetcode 1727. 重新排列后的最大子矩阵 中等
leetcode
superior tigre11 分钟前
347 前k个高频元素
数据结构·算法·leetcode
罗罗攀16 分钟前
PyTorch学习笔记|张量的索引分片、合并和维度调整
人工智能·pytorch·笔记·python·学习