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
相关推荐
chushiyunen32 分钟前
python中的@Property和@Setter
java·开发语言·python
禾小西36 分钟前
Java中使用正则表达式核心解析
java·python·正则表达式
yoyo_zzm38 分钟前
JAVA (Springboot) i18n国际化语言配置
java·spring boot·python
weixin_408099672 小时前
图片去水印 API 接口实战:网站如何实现自动去水印(Python / PHP / C#)
图像处理·人工智能·python·c#·php·api·图片去水印
yyk的萌2 小时前
AI 应用开发工程师基础学习计划
开发语言·python·学习·ai·lua
_日拱一卒3 小时前
LeetCode:最大子数组和
数据结构·算法·leetcode
qq_196976174 小时前
python的sql解析库-sqlparse
数据库·python·sql
:mnong4 小时前
Superpowers 项目设计分析
java·c语言·c++·python·c#·php·skills
a里啊里啊4 小时前
测试开发面试题
开发语言·chrome·python·xpath
豆沙糕4 小时前
Python异步编程从入门到实战:结合RAG流式回答全解析
开发语言·python·面试