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
相关推荐
爱coding的橙子10 分钟前
每日算法刷题Day27 6.9:leetcode二分答案2道题,用时1h20min
算法·leetcode·职场和发展
EverBule28 分钟前
Python 训练 day46
开发语言·python
WangY_ZQ1 小时前
Python 如何在Python 3.6上安装PIP
linux·python·pip
聚客AI1 小时前
系统掌握PyTorch:图解张量、Autograd、DataLoader、nn.Module与实战模型
人工智能·pytorch·python·rnn·神经网络·机器学习·自然语言处理
狮子也疯狂1 小时前
基于Python的气象数据分析及可视化研究
python·信息可视化·数据分析
蓝婷儿2 小时前
6个月Python学习计划 Day 18 - 项目实战 · 学生成绩管理系统(OOP版)
开发语言·python·学习
HINOTOR_2 小时前
DAY 25 异常处理
开发语言·python
yorushika_2 小时前
python打卡训练营打卡记录day49
开发语言·python·tensorboard·cbam
qq_189370492 小时前
Jupyter notebook的文章结构目录查看方式和汉化方法
python·jupyter
晨曦5432102 小时前
将 Jupyter Notebook 的默认存储路径从 C 盘迁移到 D 盘,可以通过以下步骤实现:
ide·python·jupyter