```
class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
if x<0:
return -1*self.reverse(-1*x)
elif x>2**31-1:
return 0
y=0
while x>=1:
y=10*y+x%10
x/=10
return y
```