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
相关推荐
行云流水剑20 分钟前
【学习记录】如何使用 Python 提取 PDF 文件中的内容
python·学习·pdf
心扬1 小时前
python生成器
开发语言·python
mouseliu1 小时前
python之二:docker部署项目
前端·python
狂小虎1 小时前
亲测解决self.transform is not exist
python·深度学习
Python智慧行囊2 小时前
Python 中 Django 中间件:原理、方法与实战应用
python·中间件·架构·django·开发
深科文库2 小时前
构建 MCP 服务器:第 3 部分 — 添加提示
服务器·python·chatgpt·langchain·prompt·aigc·agi
蓝婷儿2 小时前
6个月Python学习计划 Day 17 - 继承、多态与魔术方法
开发语言·python·学习
Mikhail_G2 小时前
Python应用变量与数据类型
大数据·运维·开发语言·python·数据分析
全栈凯哥2 小时前
Java详解LeetCode 热题 100(26):LeetCode 142. 环形链表 II(Linked List Cycle II)详解
java·算法·leetcode·链表