File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments