@didicout Perfect analysis! Does it means that it's just a coincidence to be correct? Once we change the max range or the radix of the int type, the solution may become error-prone?

It failed for 12210 (output true, but should be false).
Line 4 should be changed to be
if(x < 0 || (x > 0 && x%10==0)) return false;
Then it will work fine.

That's a neat answer! But why is it that we consider negative numbers to not be palindromes?
Couldn't we have checked if (x==res || x==res/10 || x+res == 0) as our return condition?

// 393 ms
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0 || x != 0 && x % 10 == 0)
return false;
int y;
for (y = 0; y < x; x /= 10)
y = y * 10 + x % 10;
return (x == y || y / 10 == x ? true : false);
}
};

The same question with me. And I test this solution just now, which shows 76ms.
And I test another solution just the same as this one but some small difference in the final block that are if(a==num) return true; else return false; This one runs for 88ms...