Simplified Python solution with O(n) complexity


  • 0
    K

    A clever way to use lists and pop() to solve the problem.

    def isPalindrome(self, s):
            
            stripped = "".join([c.lower() for c in s if c.isalnum()])
            letters = list(stripped)
             
            if len(letters) == 0:
                return True
            
            for let in letters:                
                if let != letters.pop(-1):
                    return False
        
            return True
    

Log in to reply
 

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