Geisha 2024. 8. 13. 23:49

 

코드 흐름

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;
    }
}