class Solution {
public boolean isPalindrome(int x) {
if(x<0){
return false;
}
int help=1;
while(x/help>=10){
help*=10;
}
while(x!=0){
if(x/help!=x%10){
return false;
}
x=(x%help)/10;
help/=100;
}
return true;
}
}
用x/help而不用乘法(help<n 则 help*=10)是防止溢出,x/help得到最高位,x%10得到最后一位!
x=(X%help)/10去掉首尾各一位。