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
38
39
40
41
42
43
44
45
|
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
Queue<Integer> q = new LinkedList<>();
List<Integer> list = new ArrayList<>();
int length = progresses.length;
for (int i = 0; i < length; i++) {
int sum = progresses[i];
int day = 0;
while (sum < 100) {
sum += speeds[i];
day++;
}
q.offer(day);
}
Integer now = q.poll();
int cnt = 1;
while (!q.isEmpty()) {
if (q.peek() <= now) {
cnt++;
q.poll();
} else {
list.add(cnt);
now = q.poll();
cnt = 1;
}
if (q.isEmpty()) list.add(cnt);
}
int[] ans = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
ans[i] = list.get(i);
}
return ans;
}
}
|
cs |
programmers.co.kr/learn/courses/30/lessons/42586