Simple Python solution with regexp


  • 0
    E
    class Solution(object):
        def isPalindrome(self, s):
            """
            :type s: str
            :rtype: bool
            """
            s = re.sub('[^A-Za-z0-9]+', ' ', s).strip().lower().replace(' ', '')
            return s == s[::-1]
    

Log in to reply
 

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