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
相关推荐
维度攻城狮5 小时前
ros2参数通信案例
开发语言·windows·python·ros2·参数通信
深圳佛手5 小时前
不用智能体开发框架,如何调用工具?
前端·python
Tisfy5 小时前
LeetCode 961.在长度 2N 的数组中找出重复 N 次的元素:5种语言x5种方法(及其变种) —— All By Hand
数据结构·数学·算法·leetcode·题解
清水白石0085 小时前
Python 与尾递归:为何不优化?如何优雅绕过?
开发语言·python
王大傻09285 小时前
使用python for循环与ord() + chr()实现字符串加密
开发语言·python
540_5406 小时前
ADVANCE Day35
人工智能·python·深度学习
郑泰科技6 小时前
python深度学习报错:Original error was: No module named ‘numpy.core._multiarray_umath‘
python·深度学习·numpy
不要em0啦6 小时前
从0开始学python:函数与数据容器
开发语言·python
无限码力7 小时前
华为OD技术面真题 - Python开发 -3
python·华为od·华为od技术面真题·华为od面试八股文·华为od面试python八股文·华为od技术面八股真题
0思必得07 小时前
[Web自动化] Requests模块响应的内容
运维·前端·python·自动化·html·web自动化