The most obvious idea is to maintain two divisors to get the most and least significant digits and compare them. Well, there are much more clever ideas, like , whose code is rewritten below. Play with it :-)
1 class Solution { 2 public: 3 bool isPalindrome(int x) { 4 if (x < 0 || (x && !(x % 10))) return false; 5 int s = 0; 6 while (x > s) { 7 s = s * 10 + x % 10; 8 x /= 10; 9 }10 return x == s || x == s / 10;11 }12 };