细节:
左右位数依次比较,全部相同则是回文数;否则不是。
class Solution {
public:
bool isPalindrome(int x) {
if(x < 0) return false;
int d = 1;
while(x/d >= 10) d *= 10;
while(x > 0) {
int left = x / d;
int right = x % 10;
if(left != right) {
return false;
}
x = x % d / 10;
d = d / 100;
}
return true;
}
};