3-line Python solution (using "re")


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

Log in to reply
 

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