```
class Solution {
public:
int reverse(int num) {
int sign = num < 0 ? -1 : 1;
num = num*sign;
int imax = std::numeric_limits<int>::max();
std::cout << imax << std::endl;
int rev = 0;
while (num != 0) {
if (rev <= ((imax - num%10)/10)) { rev = rev*10 + (num % 10); }
else return 0;
num = num/10;
}
return rev*sign;
}
};
```