Python Simple Solution


  • 0
    Y
    def isPalindrome(self, s):
            if s == "":
                return True
        
            pointer1 = 0
            pointer2 = len(s) - 1
        
            while pointer1 < len(s) - 1 and pointer2 > 0:
                while pointer1 < len(s) and not s[pointer1].isalnum():
                    pointer1 += 1
        
                while pointer2 > -1 and not s[pointer2].isalnum():
                    pointer2 -= 1
        
                if pointer1 < pointer2 and s[pointer1].lower() != s[pointer2].lower():
                    return False
        
                pointer1 += 1
                pointer2 -= 1
            return True

Log in to reply
 

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