和Reverse Integer类似,按位处理,而不要转换成String。
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
int base = 1;
while(x/base >= 10) base*=10;
while(x && base)
{
int highradix = x/base;
int lowradix = x%10;
if(highradix != lowradix)
return false;
x %= base;
x /= 10;
base /= 100;
}
return true;
}
};