1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| class Solution { public: bool isPalindrome(int x) { int a = x, h = 1; if (a < 0) return false; while (a / h >= 10) { h = h * 10; } while (a > 0) { if (a / h != a % 10) return false; a = a % h; a = a / 10; h = h / 100; } return true; } };
|