Determine whether an integer is a palindrome. Do this without extra space.
要考虑overflow
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
int base = 1;
while(base <= x/10) {
base *= 10;
}
while(base > 1) {
int d1 = x/base, d2 = x%10;
if(d1 != d2) return false;
x %= base;
x/= 10;
base /= 100;
}
return true;
}
};