Determine whether an integer is a palindrome. Do this without extra space.
class Solution {
public:
bool isPalindrome(int x) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if (x < 0) {
return false;
}
int oldx = x;
int newx = 0;
while (x) {
newx = newx * 10 + x % 10; // error: newx *= 10 + x % 10;
x /= 10;
}
return oldx == newx;
}
};