```
int reverse(int x) {
long result = 0;
int sign = (x >= 0) ? 0 : 1;//'+':0 '-':1
if(x == INT_MIN)
{
return 0;
}
x = abs(x);
while(x != 0)
{
result = (result*10) + (x%10);
x /= 10;
}
if(((result > INT_MAX) && (sign == 0)) || ((result > ((long)INT_MAX+1)) && (sign == 1)))
{
return 0;
}
return sign == 0 ? (int)result : (int)-result;
}
```