Determine whether an integer is a palindrome. Do this without extra space.
解题思路:
转化为字符串,然后反转判断与原字符串是否相同
Python实现:
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
if x < 0: # 负数肯定不是回文数
return False
x_str = str(x)
if x_str[::-1] != x_str:
return False
return True
a=12321
b=Solution()
print(b.isPalindrome(a)) # True