【leetcode❤python】 125. Valid Palindrome

#-*- coding: UTF-8 -*-
class Solution(object):
    def isPalindrome(self, s):
        """
        :type s: str
        :rtype: bool
        """
        s=s.lower()
        if s==None:return False
        isPalindrome1=[]
        isPalindrome2=[]
        
        for c in s:
            if (c>='a' and c<='z') or (c>='0' and c<='9'):
                isPalindrome1.append(c)
        for i in range(len(s))[::-1]:
            if (s[i]>='a' and s[i]<='z') or (s[i]>='0' and s[i]<='9'):
                isPalindrome2.append(s[i])
        
        return isPalindrome2==isPalindrome1
        
sol=Solution()
print sol.isPalindrome("ab")


原文地址:https://www.cnblogs.com/kwangeline/p/6059591.html