不能用字符串,因为不能用额外空间,那么久一位一位的造出倒过来的数再比较一下。
因为有越界问题,所以用long。
public class Solution {
public boolean isPalindrome(int x) {
if(x<0)
return false;
if(x<10)
return true;
long rst=0;
long temp=x;
long len=1;
while(x/len!=0)
{
len*=10;
}
while(len!=1)
{
rst=rst*10+temp%10;
temp=temp/10;
len/=10;
}
return rst==x;
}
}