아주 간단하다.
import java.util.PriorityQueue;
class Solution {
public int solution(int[] scoville, int K) {
PriorityQueue<Integer> prioQ = new PriorityQueue<>();
int answer = 0;
for(int i = 0; i < scoville.length; i++) {
prioQ.add(scoville[i]);
}
while(prioQ.peek() < K) {
if(prioQ.size() < 2) return -1;
prioQ.add(prioQ.poll() + (prioQ.poll() * 2));
answer++;
}
return answer;
}
}
PriorityQueue<Integer> prioQ = new PriorityQueue<>();
for(int i = 0; i < scoville.length; i++) {
prioQ.add(scoville[i]);
}
PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(Collections.reverseOrder());
int answer = 0;
while(prioQ.peek() < K) {
if(prioQ.size() < 2) return -1;
prioQ.add(prioQ.poll() + (prioQ.poll() * 2));
answer++;
}
return answer;