首页 > 编程语言 > 详细

每日LeetCode - 125. 验证回文串(Python 3)

时间:2021-06-13 01:06:37      阅读:26      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

Python3

双指针

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

 

每日LeetCode - 125. 验证回文串(Python 3)

原文:https://www.cnblogs.com/vicky2021/p/14879284.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!