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
相关推荐
qq_334563552 分钟前
PHP源码是否依赖特定芯片组_Intel与AMD平台差异【操作】
jvm·数据库·python
qq_2069013938 分钟前
如何使用C#调用Oracle存储过程_OracleCommand配置CommandType.StoredProcedure
jvm·数据库·python
m0_748839491 小时前
CSS如何实现元素平滑滚动_使用scroll-behavior属性设置
jvm·数据库·python
_深海凉_1 小时前
LeetCode热题100-除了自身以外数组的乘积
数据结构·算法·leetcode
Victoria.a1 小时前
python基础语法
开发语言·python
xiaotao1312 小时前
01-编程基础与数学基石: Python核心数据结构完全指南
数据结构·人工智能·windows·python
青苔猿猿2 小时前
【1】JupyterLab安装
python·jupyter
xiaoyaohou112 小时前
023、数据增强改进(二):自适应数据增强与AutoAugment策略
开发语言·python
鬼圣2 小时前
Python 上下文管理器
开发语言·python
努力学习_小白2 小时前
ResNet-50——pytorch版
人工智能·pytorch·python