Determine whether an integer is a palindrome. Do this without extra space.
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) //负数
return false;
int n = x;
int len = 0;
while(n)
{
len++;
n /= 10;
}
if(x >= 0 && len==1) //只有一位数字,且>=0
return true;
int i = 0;
int j = len-1;
while(i < j)
{
if( ( (x/(int)pow(10, j)) % 10 ) != ( (x/(int)pow(10, i)) % 10 ) )
return false;
i++;
j--;
}
return true;
}
};