Solution 1: accepted
The given number has to be an integer. So “if (reversed > 214748364 || reversed < -214748364)” would be fine.
Even if it is a fit, the is not a palindrome.
|
|
Solution 2: accepted 261ms
Simplified. But do we need to check the entire number?
|
|
Improvement: accepted 221ms
We only need to check half of the number12345678910public 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); // for 123321 and 12321}