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
相关推荐
踩坑记录6 分钟前
递归回溯本质
leetcode
好学且牛逼的马34 分钟前
【Hot100|25-LeetCode 142. 环形链表 II - 完整解法详解】
算法·leetcode·链表
向量引擎小橙36 分钟前
视觉艺术的“奇点”:深度拆解 Gemini-3-Pro-Image-Preview 绘画模型,看这只“香蕉”如何重塑 AI 创作逻辑!
人工智能·python·gpt·深度学习·llama
yaoxin5211231 小时前
324. Java Stream API - 实现 Collector 接口:自定义你的流式收集器
java·windows·python
独行soc1 小时前
2026年渗透测试面试题总结-24(题目+回答)
网络·python·安全·web安全·渗透测试·安全狮
SmartBrain1 小时前
Python 特性(第一部分):知识点讲解(含示例)
开发语言·人工智能·python·算法
Lun3866buzha1 小时前
基于YOLO11-C3k2-FFCM:跳甲虫害叶片智能检测与识别系统
python
Gaosiy2 小时前
技术细节-MNE读取neuroscan curry9版本cdt文件
python·脑机接口·脑电·mne
SmartBrain2 小时前
FastAPI进阶(第一部分):路由和依赖特性(含考题)
开发语言·python
nimadan122 小时前
**手机写小说软件有哪些2025推荐,适配不同创作习惯的实用
python·智能手机