코드
import java.util.Collections;
import java.util.PriorityQueue;
public class PRO_42587 {
public static int solution(int[] priorities, int location) {
int answer = 0;
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
for (int i = 0; i < priorities.length; i++) {
pq.add(priorities[i]);
}
while (!pq.isEmpty()) {
for (int i = 0; i < priorities.length; i++) {
if (priorities[i] == pq.peek()) {
if (i == location) {
answer++;
return answer;
}
pq.poll();
answer++;
}
}
}
return answer;
}
public static void main(String[] args) {
int[] priorities = {2, 1, 3, 2};
int location = 2;
System.out.println(solution(priorities, location));
}
}
풀이 및 느낀점
참고자료