- 偷懒的方式
python
class Solution:
def isPalindrome(self, x: int) -> bool:
s = str(x)
return s == s[::-1]
- 正经的方式
python
class Solution:
def isPalindrome(self, x: int) -> bool:
if x < 0 or (x % 10 == 0 and x != 0):
return False
rev = 0
temp = x
while(temp):
rev = rev * 10 + temp%10
temp = temp//10
return rev==x