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 7e50818 + 7f719e7 commit ce7204bCopy full SHA for ce7204b
ksinji/202510/16 PGM 더 맵게.md
@@ -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