Your browser does not seem to support JavaScript. As a result, your viewing experience will be diminished, and you have been placed in read-only mode.

Please download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript).

public boolean isPalindrome(int x) { if(x<0 || (x!=0 && x%10==0)) return false; int res = 0; while(x>res){ res = res*10 + x%10; x = x/10; } return (x==res || x==res/10); }

what if x = 10 ??

if x==10 then it will satisfy the if condition and given and will return false!

what is your point? it should not return false?

the point is if you are given any no that is divided by 10 then obviously its like x0 where x>=1 upto infinite! so ob 0 can be palindrome but not x0!

That's a neat answer! But why is it that we consider negative numbers to not be palindromes? Couldn't we have checked if (x==res || x==res/10 || x+res == 0) as our return condition?

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