코드
재귀 방식
def solution(n):
if n == 0 : return ''
n, remainder = divmod(n, 3)
if remainder == 0:
remainder = 4
n -= 1
return solution(n) + str(remainder)
while 방식
def solution(n):
ternary = ''
while n > 0:
n, remainder = divmod(n, 3)
if remainder == 0 :
remainder = 4
n -= 1
ternary = str(remainder) + ternary
return ternary