forked from PawanJaiswal08/leetcode-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7.reverseInteger.cpp
More file actions
30 lines (30 loc) · 763 Bytes
/
7.reverseInteger.cpp
File metadata and controls
30 lines (30 loc) · 763 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
class Solution {
public:
int reverse(int x) {
long int num = 0;
//2147483647
if( x >= 2147483647 || x <= -2147483648)
return 0;
if(x > 0){
while(x > 0){
num = num * 10;
if( num >= 2147483647 || num <= -2147483648)
return 0;
num = num + (x % 10);
x = x / 10;
}
}
else{
x = -1 * x;
while(x > 0){
num = num * 10;
if( num >= 2147483647 || num <= -2147483648)
return 0;
num = num + (x % 10);
x = x / 10;
}
num = -1 * num;
}
return int(num);
}
};