From 39bfa6d7ccab7670d4ece6a2947685214a6de80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=8B=A0=EC=A7=80?= <101992179+ksinji@users.noreply.github.com> Date: Fri, 14 Nov 2025 19:10:43 +0900 Subject: [PATCH] =?UTF-8?q?[20251114]=20PGM=20/=20LV3=20/=20=EC=97=AC?= =?UTF-8?q?=ED=96=89=EA=B2=BD=EB=A1=9C=20/=20=EA=B0=95=EC=8B=A0=EC=A7=80?= 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" | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 "ksinji/202511/14 PGM \354\227\254\355\226\211\352\262\275\353\241\234.md" diff --git "a/ksinji/202511/14 PGM \354\227\254\355\226\211\352\262\275\353\241\234.md" "b/ksinji/202511/14 PGM \354\227\254\355\226\211\352\262\275\353\241\234.md" new file mode 100644 index 00000000..ba7ed346 --- /dev/null +++ "b/ksinji/202511/14 PGM \354\227\254\355\226\211\352\262\275\353\241\234.md" @@ -0,0 +1,53 @@ +``` +import java.util.*; + +class Solution { + private String[][] tickets; + private boolean[] used; + private List answer; + private int n; + + public String[] solution(String[][] tickets) { + this.tickets = tickets; + this.n = tickets.length; + this.used = new boolean[n]; + + Arrays.sort(this.tickets, (a, b) -> { + if (!a[0].equals(b[0])) { + return a[0].compareTo(b[0]); + } + return a[1].compareTo(b[1]); + }); + + List path = new ArrayList<>(); + path.add("ICN"); + + dfs("ICN", 0, path); + + return answer.toArray(new String[0]); + } + + private boolean dfs(String current, int count, List path) { + if (count == n) { + answer = new ArrayList<>(path); + return true; + } + + for (int i = 0; i < n; i++) { + if (!used[i] && tickets[i][0].equals(current)) { + used[i] = true; + path.add(tickets[i][1]); + + if (dfs(tickets[i][1], count + 1, path)) { + return true; + } + + path.remove(path.size() - 1); + used[i] = false; + } + } + + return false; + } +} +```