https://leetcode-cn.com/problems/palindrome-number/
解题思路
计算逆数,等于原数就返回True
divmod可以优化性能
代码
class Solution(object):
def isPalindrome(self, x):
if x < 0: return False
r, tmp = 0, x
while tmp:
tmp, reminder = divmod(tmp, 10)
r = r*10 + reminder
return r == x