Python Solution with RegEx

  • 0
    import re
    class Solution(object):
    def isPalindrome(self, s):
        if len(s) < 2:
            return True
        a = re.sub(r'[^a-zA-Z0-9]','', s)
        a = a.lower()
        return a == a[::-1]

    The trick of this problem is just to use regular expression and taken care of case difference

Log in to reply

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