解题思路:
这道题目的目的是判断数字是否为回文数,注意符号也算即-121不是回文数因为-121 != 121-。
代码说明:
1、str(x)将数字转换为str。
2、str(x)[::-1] == str(x)对字符串使用切片方法使其倒序比较与源字符串是否相同。
提交代码:
class Solution:
def isPalindrome(self, x):
return str(x)[::-1] == str(x)
print(Solution().isPalindrome(-121)) #提交时请删除该行