Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions suyeun84/29 PGM LV3 여행경로.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
```
import java.util.*;

class Solution {
static String[][] tickets;
static List<String> answer = new ArrayList<>();
static int n;
static boolean[] visited;

public String[] solution(String[][] stickets) {
tickets = stickets;
n = tickets.length;
visited = new boolean[n];

dfs(0, "ICN", "ICN");
Collections.sort(answer);

return answer.get(0).split(",");
}
public static void dfs(int depth, String start, String path) {
if (depth == n) {
answer.add(path);
return;
}
for (int i = 0; i < tickets.length; i++) {
if (tickets[i][0].equals(start) && !visited[i]) {
visited[i] = true;
dfs(depth+1, tickets[i][1], path + ","+tickets[i][1]);
visited[i] = false;

}
}
}
}
```