class Solution:
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
res = str(x)
if res[0] == "-":
res = res[:0:-1]
res = '-' + res
else:
res = res[::-1]
res = int(res)
if res < -2147483648 or res > 2147483647:
res = 0
return res
Python, LeetCode, 7. 反转整数
最新推荐文章于 2018-06-08 16:57:46 发布