0009.cpp (279B)
1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 if (x < 0 || (x != 0 && x % 10 == 0)) return false; 5 int sum = 0; 6 do { 7 sum = sum * 10 + x % 10; 8 } while ((x /= 10) > sum); 9 return (x == sum) || (x == sum / 10); 10 } 11 };