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
相关推荐
小雅痞13 小时前
[Java][Leetcode middle] 73. 矩阵置零
java·leetcode·矩阵
Ulyanov13 小时前
《从质点到位姿:基于Python与PyVista的导弹制导控制全栈仿真》: 驯服猛兽——自动驾驶仪(Autopilot)设计与舵机动力学
python·自动驾驶·雷达电子对抗
暗影八度13 小时前
OpenMetadata Python ingestion 开发环境搭建与运行文档
开发语言·python
清水白石00813 小时前
从“能装上”到“可复现”:Python 团队如何正确使用 requirements.txt、锁定文件与依赖分组
开发语言·人工智能·python
jiayong2313 小时前
Python面试题集 - 基础语法与核心概念
开发语言·windows·python
05候补工程师13 小时前
ROS 2 入门:从零实现小海龟 (Turtlesim) 的手动控制与自动化绘圆
运维·经验分享·python·ubuntu·机器人·自动化
凯瑟琳.奥古斯特13 小时前
Django Flask FastAPI 三者对比
开发语言·python·django·flask·fastapi
godspeed_lucip13 小时前
LLM和Agent——专题2: LLM as Judge 入门(2)
人工智能·python
jiayong2313 小时前
Python面试题集 - 数据结构与算法
开发语言·python
十年之少13 小时前
使用VSCode 对PyQt5 say Hello—— Python + Qt 开发
vscode·python·qt