9. 回文数
为保证权益,题目请参考 9. 回文数(From LeetCode).
解决方案1
CPP
C++
#include <iostream>
#include <limits.h>
using namespace std;
class Solution
{
public:
bool isPalindrome(int x)
{
if ((x > 0 && x % 10 != 0) || x==0)
{
int x_reverse = 0;
while (x_reverse < x)
{
x_reverse = x_reverse * 10 + x % 10;
x = x / 10;
}
return x == x_reverse || x == x_reverse / 10;
}
return false;
}
};
int main()
{
Solution so;
cout << so.isPalindrome(0) << endl;
return 0;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29