class Solution:
def reverse(self, x: int) -> int:
if x < -2**31 or x > 2**31-1:
return 0
if x >= 0:
res = int(str(x)[::-1])
else:
res = -1*int(str(x)[1:][::-1])
if res < -2**31 or res > 2**31-1:
return 0
return res
github项目地址:https://github.com/JockWang/LeetCode-Python