class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
pos_x=abs(x)
a=0
while(pos_x!=0):
b=pos_x%10
a=b+a*10
pos_x=pos_x//10
if x>0 and a<=2**31-1:
return a
elif x<0 and a<=2**31:
return int('-'+str(a))
else:
return 0