From a291dfd0de315038fc710fc2cf3c60bc1d90d4b6 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Fri, 5 Sep 2025 17:03:17 +0900 Subject: [PATCH] =?UTF-8?q?[20250905]=20PGM=20/=20LV3=20/=20=EC=84=AC=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0=ED=95=98=EA=B8=B0=20/=20=EA=B9=80=EC=88=98?= =?UTF-8?q?=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\352\262\260\355\225\230\352\270\260.md" | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 "suyeun84/202509/05 PGM LV3 \354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.md" diff --git "a/suyeun84/202509/05 PGM LV3 \354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.md" "b/suyeun84/202509/05 PGM LV3 \354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.md" new file mode 100644 index 00000000..a3674179 --- /dev/null +++ "b/suyeun84/202509/05 PGM LV3 \354\204\254 \354\227\260\352\262\260\355\225\230\352\270\260.md" @@ -0,0 +1,23 @@ +```java +import java.util.*; +class Solution { + public int solution(int n, int[][] costs) { + int answer = 0; + HashSet set = new HashSet<>(); + Arrays.sort(costs, (o1, o2) -> o1[2] - o2[2]); + set.add(costs[0][0]); + while (set.size() < n) { + for (int[] cost : costs) { + if (set.contains(cost[0]) && set.contains(cost[1])) continue; + else if (set.contains(cost[0]) || set.contains(cost[1])) { + set.add(cost[0]); + set.add(cost[1]); + answer += cost[2]; + break; + } + } + } + return answer; + } +} +```