## My similar solution as yours.

```
int reverse(int x) {
unsigned int val = abs(x);
unsigned int result = 0;
while (val) {
if (result > ((unsigned int)(1 << 31) - 1) / 10)
return 0;
result = result * 10 + val % 10;
val /= 10;
}
return (x > 0 ? result : (-1 * result));
}
```