7. Reverse Integer
[Easy] “Given a 32-bit signed integer, reverse digits of an integer."
Note: old solution, should review (TODO:
)
Python3:
class Solution:
def reverse(self, x: int) -> int:
s = str(x)
max_int = 2**31 - 1
if s[0] == '-':
n = True
s = s[1:]
else:
n = False
if int(s[::-1]) < max_int:
if n:
return -int(s[::-1])
else:
return int(s[::-1])
else:
return 0