Determine whether an integer is a palindrome. Do this without extra space.
Solution:
Tips: just reverse the number then compare with initial parameter.
Java Code:
public class Solution {
public boolean isPalindrome(int x) {
if (x < 0) {
return false;
}
int result = 0;
int tmpX = x;
while (tmpX != 0) {
result = result * 10 + (tmpX % 10);
tmpX /= 10;
}
return result == x;
}
}