diff --git "a/suyeun84/29 PGM LV3 \354\227\254\355\226\211\352\262\275\353\241\234.md" "b/suyeun84/29 PGM LV3 \354\227\254\355\226\211\352\262\275\353\241\234.md" new file mode 100644 index 00000000..aae679db --- /dev/null +++ "b/suyeun84/29 PGM LV3 \354\227\254\355\226\211\352\262\275\353\241\234.md" @@ -0,0 +1,35 @@ +``` +import java.util.*; + +class Solution { + static String[][] tickets; + static List 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; + + } + } + } +} +```