https://school.programmers.co.kr/learn/courses/30/lessons/42626
import java.util.*;
class Solution {
public int solution(int[] scoville, int K) {
int answer = 0;
PriorityQueue<Integer> queue = new PriorityQueue<>();
for (int i = 0; i < scoville.length; i++) {
queue.add(scoville[i]);//큐에 저장
}
while (queue.peek() < K) {
if (queue.size() == 1) {
return -1;
}
int n = queue.poll();
int m = queue.poll();
int result = n + (m * 2);
queue.add(result);
answer++;
}
System.out.println(answer);
return answer;
}
}
// 첫번째 값을 반환하고 제거, 비어있다면 null
priorityQueueLowest.poll();
// 첫번째 값 제거 비어있다면 예외 발생
priorityQueueLowest.remove();