Easy and fast python solution using re ( beats 98%)


  • 0
    S
    import re
    
    class Solution(object):
        def isPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            if s == "":
                return True
            
            s = s.replace(" ","")
            s = re.sub(r'\W+',"",s)
            s = s.lower()
            print s
            
            if s == s[::-1]:
                return True
            
            return False
            
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.