1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
bool isPalindrome(int x) { if (x < 0) return false; if (x < 10)return true; int left = x, right = 0; if (!(left % 10))return false; while (left > right){ right = right * 10 + (left % 10); left /= 10; if ((left / 10) > 0 && (left / 10) <= right) break; } if (left == right|| (left / 10) == right)return true; return false; }
|