Python solution with no other variable introduced besides input x.

  • 4

    When I read "no extra space", I took it literally...
    In retrospect, that was foolish of me.

    def isPalindrome(self, x):
        :type x: int
        :rtype: bool
        if x<0:
            return False
        if x == 0:
            return True
        for i in range(0, int((math.floor(math.log(x,10))+1)//2 )):
            if x // 10 ** i%10 != (x // 10**(int((math.floor(math.log(x,10))))-i))%10:
                return False
        return True

  • 0

    I thought exactly like you! I really wondered how should I solve the problem without any additional variables!

Log in to reply

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