class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
ans = 0
tmp = x
while tmp != 0:
ans = ans * 10 + tmp % 10
tmp = tmp // 10
return x == ans
Time O(n). Space O(1).