Given a 32-bit signed integer, reverse digits of an integer.
要保证输出的数字是int32类型,利用int和str类型的转换解决问题
class Solution(object): def reverse(self, x): """ :type x: int :rtype: int """ if x>=0: result = int(str(x)[::-1]) else: result = int(str(abs(x))[::-1]) * (-1) if not -2**31 < abs(result) < 2**31 - 1: result = 0 return result