```
class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
reverse = 0
flag = 1
if x < 0:
x = abs(x)
flag = -1
if x == 0:
return 0
while (x != 0):
if reverse > 214748364:
return 0
remainder = x%10
reverse = reverse * 10 + remainder
x = x / 10
return reverse*flag
```