class Solution:
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
max = pow(2, 31) + 1
if abs(x) > max:
return 0
if x < 0:
flag = -1
x = abs(x)
else:
flag = 1
u = 0
z = []
while x / 10 != 0:
y = int(x % 10)
z.append(y)
x = int(x / 10)
u = 0
p = len(z)
for dx, val in enumerate(z):
u += val * pow(10, p - (dx + 1))
if u > max:
return 0
return u * flag
rev,s = 0, -1 if x < 0 else 1
x *= s
while x != 0:
rev = rev * 10 + x % 10
x //= 10
return 0 if rev > 2147483647 else s * rev
flag = -1 if x < 0 else 1
x *= flag
if x > 2147483647:
return 0
res = int(str(abs(x))[::-1])
if res > 2147483647:
return 0
else:
return res * flag