1 class Solution {
2 public:
3 int reverse(int x) {
4 list<long long>num;
5 bool mark = false;
6 if (x < 0){
7 mark = true;
8 x = -x;
9 }
10
11 while (x){
12 num.push_back(x % 10);
13 x = x / 10;
14 }
15
16 long long sum = 0;
17 while (!num.empty()) {
18 sum = sum*10+num.front();
19 num.pop_front();
20 }
21
22 if (mark)
23 sum = -sum;
24
25 int ans = sum;
26
27 if (sum > 0X7fffffff || sum < -0X7fffffff-1)
28 ans = 0;
29
30 return ans;
31 }
32 };