Determine whether an integer is a palindrome. Do this without extra space.
Show Similar Problems
The problem requirement doesn't make sense, we still need constant space to do this problem. the time complexity is O(log(n)).
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
tmp_x = x
residual = 0
while x >= 1:
rest = x % 10
residual = residual * 10 + rest
x /= 10
if tmp_x == residual:
return True
return False