-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue2.java
More file actions
37 lines (29 loc) · 891 Bytes
/
Copy pathQueue2.java
File metadata and controls
37 lines (29 loc) · 891 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
33
34
35
36
37
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
int idx = 0;
Queue<Integer> an = new LinkedList<>();
while (idx < progresses.length) {
int compleCount = 0;
for (int i = idx; i < progresses.length; i++) {
if (progresses[i] >= 100) {
compleCount++;
idx++;
} else {
break;
}
}
if (compleCount > 0) {
an.offer(compleCount);
}
for (int i = idx; i < progresses.length; i++) {
progresses[i] += speeds[i];
}
}
int[] answer = new int[an.size()];
for (int i = 0; i < answer.length; i++) {
answer[i] = an.poll();
}
return answer;
}
}