public boolean isPalindrome(int x) {
int palindromeX = 0;
int inputX = x;
while(x>0){
palindromeX = palindromeX*10 + (x % 10);
x = x/10;
}
return palindromeX==inputX;
}
Neat AC java code. O(n) time complexity.

OJ considers negative numbers as nonpalindrome. Though, your solution does not handles this case explicitly  seems to me that it is taken care of as a side effect of your algorithm. For ex: if x = 121, palindromeX = 121 by the end of the for loop which is not equal to x (121). But, there is really no need to go through the for loop, you can return false if x < 0. Otherwise, very neat solution!


@yomin we do not have to consider overflow, because when it is overflow, palindromeX !=inputX