9. A palindrome
Simple even if we simulate a walk, store each number walk is not a problem, because the comparison is only int.
But this problem provides a palindrome idea, or good.
Use the size of the front and back to see if it’s symmetrical.
public boolean isPalindrome(int x) {
if (x < 0 || (x % 10= =0&& x ! =0)) return false;
int rev = 0;
while (x > rev) {
rev = rev * 10 + x % 10;
x = x / 10;
}
return x == rev || rev / 10 == x;
}
Copy the code