Determine whether an integer is a palindrome. Do this without extra space.
bool isPalindrome(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(x<0)return false;
int left = 1, right = 10, tx = x/10;
while(tx>0)
{ tx /= 10; left *= 10;}
while(left>=right)
{
if(x/left != x%right/(right/10))return false;
x %= left; x =x - x%right; left /= 10; right *= 10;
}
return true;
}
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
long long xx = x;
long long yy = 0;
while(true){
yy = yy * 10 + xx % 10;
xx /= 10;
if(xx < 1) break;
}
return x == yy;
}
};