class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype: bool """ if x < 0 or (x != 0 and x%10 == 0): return False
y = 0 while x > y: y = y*10 + x%10 x = x/10 return x == y or y/10 == x
我提交的
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype: bool """ if x < 0: return False temp = x y = 0 while temp: y = y*10 + temp%10 temp /= 10 return x == y