From 0dafbaed4d764164292b8894f7f8e85c68605b24 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Fri, 29 Aug 2025 19:25:22 +0900 Subject: [PATCH] =?UTF-8?q?[20250829]=20PGM=20/=20LV3=20/=20=EC=97=AC?= =?UTF-8?q?=ED=96=89=EA=B2=BD=EB=A1=9C=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...54\355\226\211\352\262\275\353\241\234.md" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "suyeun84/29 PGM LV3 \354\227\254\355\226\211\352\262\275\353\241\234.md" 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; + + } + } + } +} +```