public int solution(int[] scoville, int K) {
int answer = 0;
PriorityQueue<Integer> queue = new PriorityQueue<>();
for (int s : scoville) {
queue.add(s);
}
while (queue.peek() < K) {
if (queue.size() < 2)
return -1;
int first = queue.poll();
int second = queue.poll();
int mixedScoville = first + (second * 2);
queue.add(mixedScoville);
answer++;
}
return answer;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/42626