We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents a8b9317 + a291dfd commit 5054eeaCopy full SHA for 5054eea
suyeun84/202509/05 PGM LV3 섬 연결하기.md
@@ -0,0 +1,23 @@
1
+```java
2
+import java.util.*;
3
+class Solution {
4
+ public int solution(int n, int[][] costs) {
5
+ int answer = 0;
6
+ HashSet<Integer> set = new HashSet<>();
7
+ Arrays.sort(costs, (o1, o2) -> o1[2] - o2[2]);
8
+ set.add(costs[0][0]);
9
+ while (set.size() < n) {
10
+ for (int[] cost : costs) {
11
+ if (set.contains(cost[0]) && set.contains(cost[1])) continue;
12
+ else if (set.contains(cost[0]) || set.contains(cost[1])) {
13
+ set.add(cost[0]);
14
+ set.add(cost[1]);
15
+ answer += cost[2];
16
+ break;
17
+ }
18
19
20
+ return answer;
21
22
+}
23
+```
0 commit comments