给定一个32bit的有符号整数,将这个整数倒转输出
例:
输入:123
输出:321
输入: -123
输出:-321
输入:120
输出:21
解法:
class Solution:
def reverse(self, x):
x = str(x)[::-1]
x = -int(x[:-1]) if x[-1] == '-' else int(x)
limit = pow(2, 31)
if abs(x) > limit:
return 0
return x