HTMLify
LeetCode - Reverse Integer - Python
Views: 360 | Author: abh
1 2 3 4 5 6 7 8 9 10 11 12 13 | class Solution: def reverse(self, x): if x < 0: n = -1; x = x * (-1) else: n = 1 r = 0 while x > 0: r = (r * 10) + x % 10 x//=10 r = r * n #r = int(str(x)[::-1]) * n if r < -2**31 or r > ((2**31) -1): return 0 return r |