解题思路:不断取出该整数的头尾的数字进行比较,比较完需要去除头尾的数字。
public class Solution {
public boolean isPalindrome(int x) {
if(x < 0) {
return false;
}
int len = 1;
while(x/len>=10) {
len *= 10;
}
while(x != 0) {
int left = x/len;
int right = x%10;
if(left != right) {
return false;
}
x = (x%len) /10;
len /= 100;
}
return true;
}
}