一、题目描述:
Determine whether an integer is a palindrome. Do this without extra space.
二、解题思路:
其实就是将数字通过取余的方式倒置,然后和原数字相比较,如果相等则是回文数字
三、源代码
public class Solution {
public boolean isPalindrome(int x) {
if(x<0)
return false;
else if(x==0)
return true;
else{
int temp=x;
int pal=0;
while(x!=0){
pal=pal*10+x%10;
x=x/10;
}
if(temp==pal)
return true;
else
return false;
}
}
}