-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSolution.java
More file actions
32 lines (26 loc) ยท 766 Bytes
/
Solution.java
File metadata and controls
32 lines (26 loc) ยท 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package Queue.prg42587;
import java.util.*;
class Solution {
public int solution(int[] priorities, int location) {
int N = priorities.length;
LinkedList<Integer> q = new LinkedList<>();
for (int i = 0; i < N; i++) q.offer(i);
int cnt = 0;
while (!q.isEmpty()) {
int J = q.removeFirst();
boolean print = true;
for (int i = 0; i < q.size(); i++) {
if (priorities[J] < priorities[q.get(i)]) {
q.addLast(J);
print = false;
break;
}
}
if (print) {
cnt ++;
if (J == location) return cnt;
}
}
return N;
}
}