看家本领不能丢,准备2021年每天一道leetcode题目,尽量不间隔,Python3.8
def reverse(x: int) -> int:
y, res = abs(x), 0
boundry = (1 << 31) - 1 if x > 0 else 1 << 31
while y != 0:
res = res * 10 + y % 10
if res > boundry:
return 0
y //= 10
return res if x > 0 else -res
a = 9876
print(reverse_b(a))