Skip to content

Commit 5a2ccb2

Browse files
authored
Merge pull request #1453 from AlgorithmWithGod/zinnnn37
[20251119] PGM / LV2 / 더 맵게 / 김민진
2 parents efed592 + 2dff07c commit 5a2ccb2

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
```java
2+
import java.util.PriorityQueue;
3+
import java.util.Queue;
4+
5+
public class PGM_LV2_더_맵게 {
6+
7+
private static Queue<Integer> pq;
8+
9+
public int solution(int[] scoville, int K) {
10+
int answer = 0;
11+
12+
pq = new PriorityQueue<>();
13+
14+
for (int s : scoville) {
15+
pq.offer(s);
16+
}
17+
18+
while (!pq.isEmpty() && pq.peek() < K) {
19+
if (pq.size() < 2) return -1;
20+
21+
int a = pq.poll();
22+
int b = pq.poll();
23+
24+
pq.offer(a + 2 * b);
25+
answer++;
26+
}
27+
28+
return answer;
29+
}
30+
31+
}
32+
```

0 commit comments

Comments
 (0)