# Beat 90%+ in JAVA

• `````` public boolean isPalindrome(int x) {
if (x < 0) return false;
int ans = 0;
int num = x;
while ( num > 0) {
ans = ans * 10 + num % 10;
num = num / 10;
}
if (ans != x) return false;
return true;
}``````

• Good answer! Its like reverse the Integer

• Is Integer ans & num using extra space?

• There is a problem with your solution.The max value of Integer is 2147483647,if you get this as input,the number wil overflow.

• In fact an int has reversed number overflow, it means its reverse is not an int, so it does not count as a palindrome number in the this sense. And if overflow occurs, ans will almost certainly equal to x, that is probably why his/her code could pass the test. But in reality I think an error should be thrown anyway.

• `return ans == x;`

• I always thought about comparing the two digits which are the first and the last numbers. This is quite a clear answer.

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.