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;//根据题意,小于0的直接作废
}
int divide = 1;
while(x/divide >= 10){
divide *= 10; // 选最大的除数
}
while(x != 0){
int left = x / divide;
int right = x % 10;
if(left != right){
return false;
}
x = (x % divide) / 10; //掐头去尾 12321%10000 = 2321, 2321/10=232
divide /= 100; //因为头尾一共两位所以最后要除以100
}
return true;
}
}