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
相关推荐
万添裁7 分钟前
pytorch的张量数据结构以及各种操作函数的底层原理
人工智能·pytorch·python
浔川python社18 分钟前
张雪机车:以热爱为轮,让中国摩托驰骋世界之巅
python
zl_dfq24 分钟前
Python学习5 之【字符串】
python·学习
ZC跨境爬虫34 分钟前
Python异步IO详解:原理、应用场景与实战指南(高并发爬虫首选)
爬虫·python·算法·自动化
倦王1 小时前
力扣日刷47-补
python·算法·leetcode
2501_921649491 小时前
原油期货量化策略开发:历史 K 线获取、RSI、MACD 布林带计算到多指标共振策略回测
后端·python·金融·数据分析·restful
真心喜欢你吖1 小时前
统信操作系统UOS部署安装OpenClaw+飞书接入完整教程(国产大模型配置)
人工智能·python·语言模型·大模型·openclaw·小龙虾
用户8356290780511 小时前
使用 Python 自动生成 Excel 柱状图的完整指南
后端·python
xcbrand1 小时前
口碑好的品牌策划厂家
大数据·人工智能·python