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
相关推荐
_Johnny_2 分钟前
【API Echo】API测试回调工具 - 回显请求内容
python·flask·api
知乎的哥廷根数学学派3 分钟前
基于物理约束指数退化与Hertz接触理论的滚动轴承智能退化趋势分析(Pytorch)
开发语言·人工智能·pytorch·python·深度学习·算法·机器学习
Ethan Hunt丶3 分钟前
基于Pytorch预训练模型实现声纹识别系统
人工智能·pytorch·python·语音识别
Katecat9966314 分钟前
【铁路检测】YOLO11-C3k2-StripCGLU模型在铁路轨道缺陷检测中的应用与改进
python
理想是做全栈工程师16 分钟前
基于UNet的带噪黑白数字图像分割模型
人工智能·pytorch·python·anaconda
lbb 小魔仙25 分钟前
从零搭建 Spring Cloud 微服务项目:注册中心 + 网关 + 配置中心全流程
java·python·spring cloud·微服务
霖雨28 分钟前
备份 SQL Server 到 Azure Storage
后端·python·microsoft·flask·azure
tjjucheng29 分钟前
小程序定制开发哪家有团队支持
python
我送炭你添花30 分钟前
Pelco KBD300A 模拟器:08.模板库 + 一键场景加载
运维·开发语言·python·自动化