Skip to content

Commit ee70578

Browse files
authored
[PGS] 42587 프로세스 (Lv.2)
1 parent 69eeaec commit ee70578

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

박예진/8주차/260218.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.util.*;
2+
3+
class Solution {
4+
5+
static class Process {
6+
private int idx;
7+
private int prior;
8+
9+
public Process(int idx, int prior) {
10+
this.idx = idx;
11+
this.prior = prior;
12+
}
13+
}
14+
15+
public int solution(int[] priorities, int location) {
16+
int answer = 0;
17+
18+
Queue<Process> q = new LinkedList<>(); // idx, prior
19+
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
20+
21+
for(int i = 0; i < priorities.length; i++){
22+
pq.add(priorities[i]);
23+
q.add(new Process(i, priorities[i]));
24+
}
25+
26+
while(!q.isEmpty()){
27+
Process now = q.poll();
28+
29+
// 우선순위 가장 큰 거 = 현재 우선순위
30+
if (pq.peek() == now.prior) {
31+
pq.poll();
32+
answer++;
33+
if (now.idx == location) return answer;
34+
} else {
35+
q.add(now);
36+
}
37+
}
38+
39+
return answer;
40+
}
41+
}

0 commit comments

Comments
 (0)