-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path9.cpp
More file actions
37 lines (33 loc) · 829 Bytes
/
9.cpp
File metadata and controls
37 lines (33 loc) · 829 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
// Author : Accagain
// Date : 17/2/14
// Email : chenmaosen0@gmail.com
/***************************************************************************************
*
* Determine whether an integer is a palindrome. Do this without extra space.
*
****************************************************************************************/
#include <cstdlib>
#include <cstdio>
using namespace std;
class Solution {
public:
bool isPalindrome(int x) {
if( x < 0 )
return false;
x = abs(x);
int rev = 0;
int temp = x;
while(temp)
{
rev = rev * 10 + temp % 10;
temp /= 10;
}
return (x == rev ? 1 : 0);
}
};
int main()
{
Solution * test = new Solution();
printf("%d\n", test->isPalindrome(-1321));
return 0;
}