题目描述
方法:
1. 转换为字符串
class Solution:
def isPalindrome(self, x: int) -> bool:
x = str(x)
i,j = 0,len(x)-1
while i<=j:
if x[i] != x[j]:
return False
else:
i += 1
j -= 1
return True
2. 进阶:反序数字生成
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0:
return False
cur = 0
new = x
while new > 0:
cur = new % 10 + 10 * cur
new = new//10
return x == cur