class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
if x >= 0:
tmp = int(str(x)[::-1])
return tmp if -2147483648 < tmp < 2147483647 else 0
else:
tmp = -1 * int(str(-x)[::-1])
return tmp if -2147483648 < tmp < 2147483647 else 0
Leetcode 7. 整数反转
最新推荐文章于 2022-10-16 20:59:24 发布