class Solution(object):
def reverse(self, x):
"""
:type x: int
:rtype: int
"""
uplimit = 2 ** 31 - 1
lowlimit = -1 * (2 ** 31)
if x > uplimit or x < lowlimit :
return 0
nums = []
n = abs(x)
if x > 0 :
pm = 1
elif x == 0 :
return 0
else :
pm = -1
digit = -1
result = 0
while n > 0 :
m = n % 10
n = n / 10
result = result * 10 + m
result = pm * result
if result > uplimit or result < lowlimit :
return 0
return result
궁금한점
n의 자릿수가 log n 이므로, O(log n)