Python: 5 lines, O(1) space, beats ~80% of solutions.


  • 0
    A
    def isPalindrome(self, x):
        if x < 0: return False
        orig, rev = x, 0
        while x > 0:
            x, rev = x // 10, 10*rev + x % 10
        return orig == rev
    

Log in to reply
 

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