题目描述
方法
通过字符串翻转
class Solution:
def reverse(self, x: int) -> int:
top = 2**31-1
bottom = -2**31
sign = -1 if str(x)[0] == "-" else 1
if sign == -1:
x = str(x)[1:]
else:
x = str(x)
res = int(x[::-1])
return sign*res if bottom<= sign*res <= top else 0