S E P H ' S

[Python] 124 나라의 숫자 본문

Algorithm/Programmers

[Python] 124 나라의 숫자

yoseph0310 2021. 8. 25. 23:27
 

코딩테스트 연습 - 124 나라의 숫자

 

programmers.co.kr

풀이

1. 3진법 풀이로 풀었다.

2. 다만 124중에서 반환하게 하였음.

 

def sol(n):
	if n <= 3:
    	return '124'[n-1]
    else:
    	q, r = divmod(n-1, 3)
        return sol(q) + '124'[r]

'Algorithm > Programmers' 카테고리의 다른 글

[Python] 압축  (0) 2021.08.26
[Python] 파일명 정렬  (0) 2021.08.25
[Python] 소수 찾기  (0) 2021.08.25
[Python] 가장 큰 정사각형 찾기  (0) 2021.08.24
[Python] n진수 게임  (0) 2021.08.23