Thursday, September 18, 2014

Leetcode: Valid Palindrome @Python

class Solution:
    # @param s, a string
    # @return a boolean
    def isPalindrome(self, s):
        pattern = re.compile('[\W_]+')
        A=pattern.sub('', s.lower())
        if A==A[::-1]:
            return True
        else:
            return False

No comments :

Post a Comment