๐Ÿ—๏ธ Algorithm/โฌ› ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[Programmers] [์—ฐ์Šต ๋ฌธ์ œ] [Python] Level2_124 ๋‚˜๋ผ์˜ ์ˆซ์ž

Dbswnstjd 2022. 4. 27. 18:38

๋ฌธ์ œ

https://programmers.co.kr/learn/courses/30/lessons/12899

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - 124 ๋‚˜๋ผ์˜ ์ˆซ์ž

 

programmers.co.kr

 

ํ’€์ด

# ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค 2๋‹จ๊ณ„ - 124 ๋‚˜๋ผ์˜ ์ˆซ์ž
def solution(n):
    answer = ''
    while n:
        if n % 3:
            answer += str(n%3)
            n //= 3
        else:
            answer += "4"
            n = n//3 - 1
    return answer[::-1]