Valid Palindrome

题目描述

解题方法

Solution

class Solution(object):
    def isPalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        if not s:
            return True
        length = len(s)
        left = 0
        right = length - 1
        s = s.lower()
        while left < right:
            while left < right and s[left] not in "abcdefghijklmnopqrstuvwxyz0123456789":
                left += 1
            while left < right and s[right] not in "abcdefghijklmnopqrstuvwxyz0123456789":
                right -= 1
            if s[left] == s[right]:
                left += 1
                right -= 1
            else:
                return False
        return True

Reference