Skip to content

Commit 894f07f

Browse files
authored
[20251004] PGM / LV2 / 더 맵게 / 이인희
1 parent ecfb8ca commit 894f07f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)