leetcode腾讯精选009
题目:https://leetcode-cn.com/problems/palindrome-number/
代码:
class Solution {
public:
bool isPalindrome(int x) {
bool res = true;
if (x < 0)
{
return false;
}
int dig = log10(x);
int index = 0;
int rev;
while (index < dig)
{
int a = pow(10, index + 1);
int single_dig = (x % a)/pow(10,index);
int t = pow(10, dig - index);
int high_dig = (x / t)%10;
if (single_dig != high_dig)
{
res = false;
break;
}
index++;
}
return res;
}
};
结果: