c++
class Solution {
public:
bool isPalindrome(int x) {
if (x < 0) return false;
string reverseStr;
string str;
int2string(x, reverseStr, str);
return reverseStr == str;
}
private:
void int2string(int x, string &reverseStr, string &str) {
while (x > 0) {
reverseStr.push_back(x % 10);
x /= 10;
}
str = reverseStr;
reverse(str.begin(), str.end());
}
};
python
class Solution(object):
def isPalindrome(self, x):
"""
:type x: int
:rtype: bool
"""
s = str(x)
x = s[::-1]
return s==x