- Question Description
- My Key
package LeetCode;
public class Test {
public static void main(String[] args) {
System.out.println(isPalindrome(121)?1:0);
}
public static boolean isPalindrome(int x) {
if (x < 0)
return false;
int temp = x;
int rev = 0;
int a = 0;
while (temp/10 != 0) {
a = temp%10;
rev += a;
if (rev > Integer.MAX_VALUE/10 || (rev == Integer.MAX_VALUE/10 && a > 7)) {
return false;
}
rev *= 10;
temp /= 10;
}
rev += temp;
return (x == rev)? true:false;
}
}