[Leetcode]Palindrome Number

时间:2021-11-09 00:13:40

Determine whether an integer is a palindrome. Do this without extra space.

这题貌似解法挺多,直接用简单的把数倒置,没有考虑数据溢出的问题,如需解决可以把转置数设为long long即可。另外方法可以用到前后匹配、递归比较等。

 class Solution {
public:
bool isPalindrome(int x) {
int a=x;
int n=;
if(x<)
return false;
while(x)
{
n*=;
n+=x%;
x/=;
}
if(n==a)
return true;
else return false;
}
};