코드 흐름
https://www.youtube.com/watch?v=vq7dpFWpwAE
위 영상을 보고 문제를 풀이 하였다.
import java.util.*;
class Solution {
ArrayList<int[]> list = new ArrayList<>();
public void hanoi(int n, int from, int mid, int to){
if(n == 0)
return;
hanoi(n-1,from,to,mid);
list.add(new int[]{from,to});
hanoi(n-1,mid,from,to);
}
public int[][] solution(int n) {
int[][] answer = {};
hanoi(n,1,2,3);
answer = list.stream().toArray(int[][]::new);
return answer;
}
}
'Algorithm & Data Structures > Programers' 카테고리의 다른 글
Lv 2. 배달 (0) | 2024.08.20 |
---|---|
Lv 2. 전력망을 둘로 나누기 (1) | 2024.08.19 |
Lv 2. 숫자 카드 나누기 (0) | 2024.08.12 |
Lv 2. 메뉴 리뉴얼 (0) | 2024.08.11 |
Lv 2. 호텔 대실 (0) | 2024.08.09 |