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
相关推荐
深蓝AI10 分钟前
HTTPX 超时 1 秒,接口为何还能跑 2.4 秒?
python
CyrusYiVPP17 分钟前
哪个用户会再来买?RFM模型+plotly画出用户分层,数据分析实战第2期
人工智能·python
文丑颜不良啊1 小时前
LeetCode1961~1980题目解析
java·leetcode
文丑颜不良啊1 小时前
LeetCode2001~2020题目解析
java·leetcode
李帅5152 小时前
用 CPU 做发票识别:从 OCR 文本行到结构化明细表的 4 个硬骨头
python
happylifetree3 小时前
Python79:核心语法-面向对象基础-实例方法
python
贝壳6903 小时前
bool-hybrid-array 9.13.6 偷偷加了个"按键自动升序"的字典,我翻出来测了下
python
艺杯羹4 小时前
MCP本地服务集成避坑:从Stdio管道僵死到双向JSON-RPC稳健通信
人工智能·python·ai·系统架构·大语言模型·ai编程·mcp
happylifetree4 小时前
Python78:核心语法-面向对象基础-类与对象
python
duansamve4 小时前
Python中进程
python