class Solution:
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
value = 0
if x >= 2147483647 or x <= -2147483647:
return 0
try:
if x > 0:
value = int(str(x)[::-1])
elif x < 0:
value = -int(str(-x)[::-1])
if value >= 2147483647 or value <= -2147483647:
return 0
return value
except OverflowError:
return 0
No comments:
Post a Comment