题目

Determine whether an integer is a palindrome. Do this without extra space.

Python

1
2
3
4
5
6
7
8
9
10
class Solution:
def isPalindrome(self, x):
if x < 0 or (x%10 == 0 and x != 0):
return false
r = 0
while x > r:
r = r*10 + x%10
x = x // 10
return x == r or x == r//10