Determine whether an integer is a palindrome. Do this without extra space.
题意:判断一个数是不是回文数。
通常情况下,我们可以把这个数转化为一个字符串,然后反转,判断相等。但题目要求不能使用额外空间,所以,抛弃。我的想法是循环将数字反转,比较。
public class Solution {
public boolean isPalindrome(int x) {
int s=x;
int r=0;
if(x<0){
return false;
}
while(s!=0){
r=r*10+s%10;
s/=10;
}
return r==x;
}
}