class Solution(object):

def reverse(self, x):

"""

:type x: int

:rtype: int

"""

sign = 1 if x > 0 else -1

x = abs(x)

```
y = 0
while x > 0:
y = y * 10 + x % 10
x = x / 10
if abs(sign * y) > (2 ** 31):
return 0
return sign * y
```