🔗 프로세스
import java.util.*; import java.util.Collections; class Solution { public int solution(int[] priorities, int location) { // index를 담는 큐 Queue<int[]> queue=new LinkedList<>(); for(int i=0;i<priorities.length;i++){//priorities 저장 queue.offer(new int []{priorities[i],i} );// {우선순위, index} } // poll 할때 큰 순으로 나오도록 Queue<Integer> maxQueue=new PriorityQueue<>(Collections.reverseOrder()); for(int p: priorities){//우선순위 저장 maxQueue.offer(p); } // 몇 번째로 실행되는 지 int count =0; // 큐에 값이 없을 때까지 반복 while(!queue.isEmpty()){ // 해당 i 프로세스의 우선순위 ({우선순위, 인덱스}) int []priority=queue.poll(); // 우선순위 최댓값 int maxPriority=maxQueue.peek(); // 우선순위가 더 큰게 큐에 아직 있다면 if(maxPriority>priority[0]){ // 뒤에 넣기 queue.offer(priority); continue; } // 실행될 것이고 location 과 같다면 else if(priority[1]==location){ // 실행 count ++; return count; } // location 과 같지 않고 단순히 실행 된다면 else{ // max queue 업데이트 maxQueue.poll(); // 실행 count++; } } return count; } }
'코딩테스트 > 문제풀이' 카테고리의 다른 글
[ 프로그래머스 ] #42747 : H-Index - JAVA (0) | 2025.04.07 |
---|---|
[ 프로그래머스 ] #81303 : 표 편집 - JAVA (0) | 2025.04.05 |
[ 프로그래머스 ] #42583 : 다리를 지나는 트럭 - JAVA (1) | 2025.04.03 |
[ 프로그래머스 ] #64061 : 크레인 인형뽑기 게임 - JAVA (0) | 2025.04.02 |
[ 프로그래머스 ] #76502 : 괄호 회전하기 - JAVA (1) | 2025.03.31 |