Skip to content

Commit c78e35a

Browse files
committed
Programmers_12946 : 하노이의 탑
1 parent 48bfc96 commit c78e35a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
5+
private List<int[]> arr;
6+
7+
public int[][] solution(int n) {
8+
arr = new ArrayList<>();
9+
hanoi(1, 2, 3, n);
10+
int[][] answer = arr.stream().toArray(int[][]::new);
11+
return answer;
12+
}
13+
14+
public void hanoi(int from, int mid, int to, int n) {
15+
if(n == 0) {
16+
return;
17+
}
18+
19+
hanoi(from, to, mid, n-1);
20+
arr.add(new int[]{from, to});
21+
hanoi(mid, from, to, n-1);
22+
}
23+
}

0 commit comments

Comments
 (0)