判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。
先翻转再判断,好像有点复杂
class Solution {
public boolean isPalindrome(int x) {
if(x==0)
return true;
if(x>0){
int rex = reverse(x);
return x==rex;
}
return false;
}
public int reverse(int x){
int res=0;
while(x!=0){
int remainder = x%10;
x=x/10;
if(res>Integer.MAX_VALUE/10||res<Integer.MIN_VALUE/10){
return 0;
}
res = res*10 + remainder;
}
return res;
}
}
原文:https://www.cnblogs.com/jackiez/p/13577009.html