My 360ms answer in python


  • 0
    A

    It's faster to not change the number itself:

    class Solution:
        # @return a boolean
        def isPalindrome(self, x):
            if x == 0:
                return True
            if x < 0:
                return False
            maxpower = int(math.log10(x))
            for i in range(maxpower//2+1):
                if (x // 10**(maxpower-i)) % 10 != (x % 10**(i+1)) // 10**i:
                    return False
            return True

Log in to reply
 

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