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
相关推荐
橘颂TA5 小时前
【剑斩OFFER】算法的暴力美学——二进制求和
算法·leetcode·哈希算法·散列表·结构与算法
Edward.W6 小时前
Python uv:新一代Python包管理工具,彻底改变开发体验
开发语言·python·uv
小熊officer6 小时前
Python字符串
开发语言·数据库·python
月疯6 小时前
各种信号的模拟(ECG信号、质谱图、EEG信号),方便U-net训练
开发语言·python
小鸡吃米…7 小时前
机器学习中的回归分析
人工智能·python·机器学习·回归
AC赳赳老秦7 小时前
Python 爬虫进阶:DeepSeek 优化反爬策略与动态数据解析逻辑
开发语言·hadoop·spring boot·爬虫·python·postgresql·deepseek
浩瀚之水_csdn7 小时前
Python 三元运算符详解
开发语言·python
Yuner20007 小时前
Python机器学习:从入门到精通
python
尋有緣7 小时前
力扣1355-活动参与者
大数据·数据库·leetcode·oracle·数据库开发
Amelia1111118 小时前
day47
python