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.
1 parent ecfb8ca commit 894f07fCopy full SHA for 894f07f
LiiNi-coder/202511/04 PGM 더 맵게.md
@@ -0,0 +1,25 @@
1
+```java
2
+import java.util.*;
3
+
4
+class Solution {
5
+ public int solution(int[] scoville, int K) {
6
+ int answer = 0;
7
+ Queue<Integer> q = new PriorityQueue<Integer>();
8
+ for(int s: scoville){
9
+ q.offer(s);
10
+ }
11
+ boolean isImpossible = false;
12
+ while(q.peek() < K){
13
+ if(q.size() < 2){
14
+ isImpossible = true;
15
+ break;
16
17
+ int s1 = q.poll();
18
+ int s2 = q.poll();
19
+ q.offer(s1 + s2*2);
20
+ answer++;
21
22
+ return (isImpossible)? -1 : answer;
23
24
+}
25
+```
0 commit comments