프로그래머스/Lv. 1

15. 하노이 탑 ★

Seohyeong Lee 2024. 7. 12. 01:45

유명한 재귀 문제.

유형 : recursion

 

def hanoi(n, dep, by, des):
    if n == 1:
        return [[dep, des]]
    res = hanoi(n-1, dep, des, by)+ [[dep, des]] + hanoi(n-1, by, dep, des)
    return res
def solution(n):
    answer = hanoi(n, 1, 2, 3)
    return answer

 

하 근데 리스트 처리 때문에 애 좀 먹었다...

파이썬 리스트에 더 익숙해져야 할 것 같다.