```
class Solution(object):
def reverse(self, x):
s=0
if(x<0):
s=1
x=-x
if x==0:
return 0
n=x
a=[]
while n>0:
a.append(n%10)
n/=10
sum=0
for i in range(len(a)):
sum=sum*10+a[i]
if sum>2147483647:
return 0
if(s==1):
return -sum
return sum
```