[LC] 125. Valid Palindrome

        Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

        Note: For the purpose of this problem, we define empty string as valid palindrome.

        Example 1:

        Input: "A man, a plan, a canal: Panama"
        Output: true
        

        Example 2:

        Input: "race a car"
        Output: false

        class Solution(object):
            def isPalindrome(self, s):
                """
                :type s: str
                :rtype: bool
                """
                if s is ‘‘:
                    return True
                import string
                valid = set(string.ascii_letters + string.digits) 
                s_cp = s[:].lower()
                left, right = 0, len(s) - 1
                while left <= right:
                    if s_cp[left] not in valid:
                        left += 1
                    elif s_cp[right] not in valid:
                        right -= 1
                    elif s_cp[left] != s_cp[right]:
                        return False
                    else:
                        left += 1
                        right -= 1
                return True
        相关文章
        相关标签/搜索
        4887铁算盘一句解特马香港马会开码结果直播 开奖结果-香港最快开奖现场直播-王中王资料 一肖中特-2018年管家婆彩图