给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false 。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。例如,121 是回文,而 123 不是。
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
str_x = str(x)
if str_x == str_x[::-1]:
return True
else:
return False
将数字转化为字符串,利用字符串反转的效果,和上一题整数反转很相似。