public class Solution {
public boolean isPalindrome(int x) {
if (x < 0) {
return false;
}
return x == reverse(x);
}
private int reverse (int x) {
int result = 0;
while (x != 0) {
int newResult = result * 10 + x % 10;
x = x / 10;
if (newResult / 10 != result) {
result = 0;
break;
}
result = newResult;
}
return result;
}
}
Palindrome Number
最新推荐文章于 2017-07-20 20:20:47 发布