class Solution:
def reverse(self, x):
if x < 0: n = -1; x = x * (-1)
else: n = 1
r = 0
while x > 0:
r = (r * 10) + x % 10
x//=10
r = r * n
#r = int(str(x)[::-1]) * n
if r < -2**31 or r > ((2**31) -1): return 0
return r