public int solution(int[] priorities, int location) {
Queue<Integer> queue = new LinkedList<>();
int[] counts = new int[10];
int answer = 0;
for (int i = 0; i < priorities.length; i++) {
queue.offer(i);
counts[priorities[i]]++;
}
int priority = 9;
while (!queue.isEmpty()) {
int currentDoc = queue.poll();
while (counts[priority] == 0) {
priority--;
}
if (currentDoc == location && priority == priorities[currentDoc]) {
answer++;
break;
}
if (priorities[currentDoc] < priority) {
queue.offer(currentDoc);
} else {
answer++;
counts[priorities[currentDoc]]--;
}
}
return answer;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/42587