My python solution with only one other space


  • 2
    R
    class Solution:
        # @return a boolean
        def isPalindrome(self, x):
            if x < 0:
                return False
            length = 1
            while x >= length:
                length *= 10
            length /= 10
            while x:
                if x % 10 != x / length:
                    return False
                x = (x % length) / 10
                length /= 100
            return True

  • 0
    S

    does variable "length" count as extra space?


  • 0
    S

    I think so! It counts and costs extra space. But I can't figure out how to solve this problem without introducing other variables.


Log in to reply
 

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