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
相关推荐
CoLiuRs18 分钟前
语义搜索系统原理与实现
redis·python·向量·es
zhihuaba21 分钟前
使用PyTorch构建你的第一个神经网络
jvm·数据库·python
u01092727122 分钟前
Python Web爬虫入门:使用Requests和BeautifulSoup
jvm·数据库·python
Stream_Silver1 小时前
【Agent学习笔记3:使用Python开发简单MCP服务】
笔记·python
穿过锁扣的风1 小时前
零基础入门 Python 爬虫:从基础到实战,爬取虎扑 / 豆瓣 / 图片全掌握
开发语言·爬虫·python
Stream_Silver1 小时前
【Agent学习笔记2:深入理解Function Calling技术:从原理到实践】
笔记·python
love530love2 小时前
技术复盘:llama-cpp-python CUDA 编译实战 (Windows)
人工智能·windows·python·llama·aitechlab·cpp-python·cuda版本
逄逄不是胖胖2 小时前
《动手学深度学习》-60translate实现
人工智能·python·深度学习
橘颂TA2 小时前
【测试】自动化测试函数介绍——web 测试
python·功能测试·selenium·测试工具·dubbo
爱学习的阿磊3 小时前
Python上下文管理器(with语句)的原理与实践
jvm·数据库·python