[LeetCode] 9 - Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0) {
return false;
}
if(x < 10) {
return true;
}
int base0 = 1;
int base1 = 1;
int x1 = x;
while (x1 >= 10) {
x1 /= 10;
base1 *= 10;
}
while (base1 > base0) {
int low = (x / base0) % 10;
int high = (x / base1) % 10;
if (low != high) {
return false;
}
base0 *= 10;
base1 /= 10;
}
return true;
}
};