Determine whether an integer is a palindrome. Do this without extra space.
判断一个整数是否是回文数。
思路:求出数字abcd的逆序的数值dcba,如果是回文数的话,那么abcd==dcba。
时间复杂度:O(n)
python代码:
1 class Solution(object): 2 def isPalindrome(self, x): 3 """ 4 :type x: int 5 :rtype: bool 6 """ 7 temp = x 8 revert_x = 0 9 while temp > 0:10 revert_x = revert_x*10 + temp % 1011 temp //= 1012 return revert_x == x