Leetcode 9. Palindrome Number(python)
判断一个整数是否是回文数。不可以用额外的空间
我的思路很简单。就是计算首和尾,检测是否相同
class Solution(object): def isPalindrome(self, x): if x<0: return False i,a=0,x while a!=0: a=a/10 i+=1 first_i=10**(i-1) last_i=10 while first_i>=last_i: first=x/first_i last=x%last_i if first!=last: return False x%=first_i x/=last_i first_i/=100 return True