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:
    def isPalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        if len(s)==0:
            return True
        str = []
        for i in s:
            if i.isalnum():
                str.append(i.lower())
        for i in range(int(len(str)/2)):
            if str[i]!= str[len(str)-i-1]:
                return False
        return True
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号