python3
题目:
Given a 32-bit signed integer, reverse digits of an integer.
Assume we are dealing with an environment which could only store integers within the 32-bit signed integer range: [−231, 231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.
代码:Runtime: 56 ms
class Solution:
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
x=int(str(x)[::-1]) if x >=0 else - int(str(-x)[::-1])
return x if x < 2**31 and x >= -2**31 else 0