forked from cpselvis/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution009.cpp
More file actions
58 lines (50 loc) · 779 Bytes
/
solution009.cpp
File metadata and controls
58 lines (50 loc) · 779 Bytes
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @file Palindrome number
* cpselvis([email protected])
* 2016.7.30
*/
#include<iostream>
using namespace std;
class Solution {
public:
bool isPalindrome(int x) {
// negative integers
if( x < 0 )
{
return false;
}
if( x == 0 )
{
return true;
}
if (x == reverse(x))
{
return true;
}
else
{
return false;
}
}
int reverse(int x)
{
int result = 0;
// Overflow situation
if (x < INT_MIN || x > INT_MAX )
{
return 0;
}
while (x / 10 > 0)
{
result = result * 10 + x % 10;
x /= 10;
}
result = result * 10 + x;
return result;
}
};
int main(int argc, char **argv)
{
Solution s;
cout << s.isPalindrome(1534334351) << endl;
}