Determine whether an integer is a palindrome. Do this without extra space.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class Solution {
public:
bool isPalindrome(int x) {
const int MAXX=0x7fffffff;
if (x < 0) {
return false;
}
int sum = 0, isPalin = 1, copy=x;
while(x > 0) {
int cnt = x%10;
if(MAXX/10 < sum) {
isPalin=0;
break;
}
sum = sum*10+cnt;
x = x/10;
if(sum < 0) {
isPalin = 0;
break;
}
}
if(isPalin == 1) {
if(copy == sum) isPalin = 1;
else isPalin = 0;
}
return isPalin == 1;
}
}