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