Programmers 3진법 뒤집기

Solution

def solution(n):
    temp = ''
    while n > 0:
        n, mod = divmod(n, 3)
        temp += str(mod)
    return int(temp, 3)
  • 다른 사람 풀이
def solution(n):
    tmp = ''
    while n:
        tmp += str(n % 3)
        n = n // 3

    answer = int(tmp, 3)
    return answer