思路:
看当前数字的反数字(reverse)是否和原数字相等
bool isPalindrome(int x) {
if (x < 0) return false;
if (! x) return true;
int n1 = 0, n2 = x;
while (x) {
n1 = n1 * 10 + x % 10;
x /= 10;
}
return n1 == n2;
}
思路:
看当前数字的反数字(reverse)是否和原数字相等
bool isPalindrome(int x) {
if (x < 0) return false;
if (! x) return true;
int n1 = 0, n2 = x;
while (x) {
n1 = n1 * 10 + x % 10;
x /= 10;
}
return n1 == n2;
}