Determine whether an integer is a palindrome. Do this without extra space.
检查一个整数是否回文
根据回文数的特点 ,逆向相同,取收尾比较
考虑奇数位与偶数位回文的区别,注意处理特殊情况
class Solution {
public:
bool isPalindrome(int x) {
if (x<0||(x!=0 && x%10==0))return false;
int sum=0;
while(x>sum){
sum=sum*10+x%10;
x=x/10;
}
return (x==sum)||(x==sum/10);
}
};