Skip to content

Commit ce7204b

Browse files
authored
Merge pull request #1139 from AlgorithmWithGod/ksinji
[20251016] PGM / LV2 / 더 맵게 / 강신지
2 parents 7e50818 + 7f719e7 commit ce7204b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

ksinji/202510/16 PGM 더 맵게.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(int[] scoville, int K) {
6+
PriorityQueue<Integer> pq = new PriorityQueue<>();
7+
8+
for (int i: scoville){
9+
pq.add(i);
10+
}
11+
12+
int answer = 0;
13+
14+
while (!pq.isEmpty() && pq.peek() < K) {
15+
// pq의 크기가 2 미만이면 음식 섞기 불가
16+
// 근데 모든 음식의 스코빌 지수가 아직 K 이상이 아니므로 -1 리턴
17+
if (pq.size() < 2){
18+
return -1;
19+
}
20+
21+
int first = pq.poll();
22+
int second = pq.poll();
23+
int newS = first + (second*2);
24+
25+
pq.add(newS);
26+
answer++;
27+
}
28+
29+
return answer;
30+
}
31+
}
32+
```

0 commit comments

Comments
 (0)