```
public class Solution {
public int Reverse(int x) {
bool neg = x < 0 ? true : false;
if (neg)
x *= -1;
int result = 0;
while ( x > 0)
{
if (result > 0 && int.MaxValue / result < 10)
return 0;
result *= 10;
result += (x % 10);
x /= 10;
}
if (neg)
result *= -1;
return result;
}
```

}