给定一个 32 位有符号整数,将整数中的数字进行反转。
1 class Solution: 2 def reverse(self, x): 3 """ 4 :type x: int 5 :rtype: int 6 """ 7 bool = False 8 if x < 0: 9 bool = True 10 if bool: 11 num = int("-"+str(x)[1:][::-1]) 12 else: 13 num = int(str(x)[::-1]) 14 15 if -2 ** 31 <= num <= 2 ** 31 - 1: 16 return num 17 else: 18 return 0 19 20 21 22