Determine whether an integer is a palindrome. Do this without extra space.
思路:将数字的右半边逆序记录下来,与左半边比较。
public class Solution {
public boolean isPalindrome(int x) {
if (x < 0 || (x != 0 && x %10 == 0)) return false;
int reverse = 0;
while (x > reverse) {
reverse = reverse * 10 + x % 10;
x /= 10;
}
return (x == reverse) || (x == reverse / 10);
}
}