```
class Solution:
def reverse(self, x):
"""
:type t: int
:rtype: int
"""
res = 0
y = abs(x)
while (y != 0):
res = 10 * res + y % 10
y = int(y / 10)
if res < -(2 ** 31) + 1 or res > (2 ** 31) - 1:
return 0
return res if x > 0 else res * (-1)
```