```
int reverse(int x) {
long long num = x;
int n_flag = 1;
long long result = 0;
if (x < 0) {
num = -x;
n_flag = -1;
}
while( num > 0 ) {
result = result * 10 + num % 10;
num /= 10;
}
if ( result > 0x7FFFFFFF || result < (-0x7FFFFFFF - 1) ) {
return 0;
}
return n_flag * result;
}
```