leetcode刷题记--ReverseInteger-续
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 class Solution: def reverse(self, x): # 取出符号位 sign = -1 if x<0 else 1 # 把x化为正数 x*=sign rev = 0 while not x==0: rev*=10 rev += x%10 x = x//10 if not -2**31<=rev<=2**31-1: return 0 return rev*sign 上面代码是在lee