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 小时前
pip install mxnet 报错解决方案
python·pip·mxnet
I_LPL6 小时前
hot100贪心专题
数据结构·算法·leetcode·贪心
不只会拍照的程序猿7 小时前
《嵌入式AI筑基笔记02:Python数据类型01,从C的“硬核”到Python的“包容”》
人工智能·笔记·python
Jay_Franklin7 小时前
Quarto与Python集成使用
开发语言·python·markdown
Oueii8 小时前
Django全栈开发入门:构建一个博客系统
jvm·数据库·python
2401_831824968 小时前
使用Fabric自动化你的部署流程
jvm·数据库·python
njidf8 小时前
Python日志记录(Logging)最佳实践
jvm·数据库·python
@我漫长的孤独流浪8 小时前
Python编程核心知识点速览
开发语言·数据库·python
宇擎智脑科技9 小时前
A2A Python SDK 源码架构解读:一个请求是如何被处理的
人工智能·python·架构·a2a
2401_851272999 小时前
实战:用Python分析某电商销售数据
jvm·数据库·python