Accepted python code (69 ms)

  • 0
    def isPalindrome(self, s):
        :type s: str
        :rtype: bool
       #s = "A man, a plan, a canal: Panama"
       #new_s = "amanaplanacanalpanama"
        if not s: return True #empty string
        new_s = ''.join([i for i in s if i.isalnum() ]).lower()
        return new_s == new_s[::-1] #reverse

Log in to reply

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