7.整数反转
7.整数反转
方法一
class Solution: def reverse(self, x): """ :type x: int :rtype: int """ flag = 0 if x < 0: flag = 1 x = abs(x) res = 0 while x > 0: res = res * 10 temp = x % 10 res += temp x = x // 10 if res < (-2) ** 31 or res > (2) ** 31 -1: return 0 if flag == 1: return -res return res