Determine whether an integer is a palindrome. Do this without extra space.
Negative number is not palindrome, then compare reversed(int) == int.
public boolean isPalindrome(int x) {
//negative number is not a palindrome
if (x<0) {
return false;
}
long number = x;
long reverse = 0;
while (number!=0) {
long remainder = number%10;
reverse = reverse * 10 + remainder;
number = number / 10;
}
return x==reverse;
}