import Foundation
func solution(_ n:Int) -> [[Int]] {
var result: [[Int]] = []
func hanoi(_ n:Int, _ from: Int, _ by: Int, _ to: Int) {
if n == 1 {
result.append([from, to])
return
}
hanoi(n-1, from, to, by)
hanoi(1, from, by, to)
hanoi(n-1, by, from, to)
}
hanoi(n, 1, 2, 3)
return result
}
'프로그래머스 > Lv.2' 카테고리의 다른 글
[Swift] 문자열 압축 (0) | 2023.06.23 |
---|---|
[Swift] 시소 짝궁 (0) | 2023.06.23 |
[Swift] 숫자 카드 나누기 (0) | 2023.06.18 |
[Swift] 멀쩡한 사각형 (0) | 2023.06.17 |
[Swift] 호텔 대실 (1) | 2023.06.17 |