-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
43 lines (35 loc) · 720 Bytes
/
main.cpp
File metadata and controls
43 lines (35 loc) · 720 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
#include <string>
#include <iostream>
#include <algorithm>
#define lower -2147483648
#define upper 2147483647
class Solution
{
public:
int reverse(int x)
{
std::string sx = x < 0 ? "-" : "";
sx += std::to_string(abs(x));
if (x < 0)
{
std::reverse(sx.begin() + 1, sx.end());
}
else
{
std::reverse(sx.begin(), sx.end());
}
long long lx = stol(sx);
if (lower <= lx && lx <= upper)
{
return (int)lx;
}
return 0;
}
};
int main()
{
Solution model = Solution();
int reversed = model.reverse(-124265343);
std::cout << reversed << std::endl;
return 0;
}