9. Palindrome Number
- 全部反向可能会overflow
- edge cases: negative number; 100,200...
- 将低位反向构成数字,和高位相比
public boolean isPalindrome(int x) {
if (x < 0 || (x != 0 && x % 10 == 0)) return false;
int revLow = 0;
while (x > revLow) {
revLow = revLow * 10 + x % 10;
x = x / 10;
}
return x == revLow || x == revLow / 10;
}