Skip to content

Commit 11ea1d0

Browse files
authored
Create 프로그래머스_프로세스.java
1 parent fcd66ac commit 11ea1d0

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.util.*;
2+
class Solution {
3+
public int solution(int[] priorities, int location) {
4+
int answer = 1;
5+
Queue<int[]> q = new LinkedList<>();
6+
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
7+
for (int i = 0 ; i < priorities.length ; i++) {
8+
q.offer(new int[]{i, priorities[i]});
9+
pq.offer(priorities[i]);
10+
}
11+
12+
while(!q.isEmpty()) {
13+
int [] a = q.peek();
14+
15+
if (a[1] >= pq.peek()) {
16+
if (a[0] == location) {
17+
18+
return answer;
19+
}
20+
21+
q.poll();
22+
pq.poll();
23+
answer++;
24+
} else {
25+
q.poll();
26+
q.offer(a);
27+
}
28+
}
29+
30+
return answer;
31+
}
32+
}

0 commit comments

Comments
 (0)