Skip to content

Commit 0dafbae

Browse files
authored
[20250829] PGM / LV3 / 여행경로 / 김수연
1 parent 3199f02 commit 0dafbae

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
```
2+
import java.util.*;
3+
4+
class Solution {
5+
static String[][] tickets;
6+
static List<String> answer = new ArrayList<>();
7+
static int n;
8+
static boolean[] visited;
9+
10+
public String[] solution(String[][] stickets) {
11+
tickets = stickets;
12+
n = tickets.length;
13+
visited = new boolean[n];
14+
15+
dfs(0, "ICN", "ICN");
16+
Collections.sort(answer);
17+
18+
return answer.get(0).split(",");
19+
}
20+
public static void dfs(int depth, String start, String path) {
21+
if (depth == n) {
22+
answer.add(path);
23+
return;
24+
}
25+
for (int i = 0; i < tickets.length; i++) {
26+
if (tickets[i][0].equals(start) && !visited[i]) {
27+
visited[i] = true;
28+
dfs(depth+1, tickets[i][1], path + ","+tickets[i][1]);
29+
visited[i] = false;
30+
31+
}
32+
}
33+
}
34+
}
35+
```

0 commit comments

Comments
 (0)