public class Solution {

public int Reverse(int x) {

```
int result = 0;
var negtive = x < 0;
if(x==int.MinValue)
return 0;
if(x < 0)
{
x = 0 - x;
}
while(x != 0)
{
//handle overflow
if((result>int.MaxValue/10)||(result==int.MaxValue/10&&x>int.MaxValue%10))
return 0;
result = result*10 + x%10;
x = x / 10;
}
return negtive ? 0 - result : result;
}
```

}