方法一:观察法
bool isPalindrome(int x) {
int64_t cur = 0;
int num = x;
if (x < 0)
return false;
while (num != 0)
{
cur = cur * 10 + num % 10;
num = num / 10;
}
return cur==x;
}
方法二:转成字符串
bool isPalindrome(int x) {
std::string cur = std::to_string(x);
std::string rcur = cur;
std::reverse(rcur.begin(),rcur.end());
return rcur == cur;
}