Example 1:
Input: 121
Output: true
Example 2:
Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
class Solution:
def isPalindrome(self, x: int) -> bool:
if (x>=0):
return x==int(str(x)[::-1])
else :
return False
老师 int(str(x)[::-1]) 这一行可以解释下具体意思吗 从后向前读取元素 最后要把string类型转为int类型 吗?
展开