回文数:
判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
1. 转成字符串解题
class Solution:
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
if x<0: #所有负数都不是回文数
return False
else:
a = str(x) #转成字符串
b = a[::-1] #倒序排列
if a==b:
return True
else:
return False