-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSolution.java
More file actions
57 lines (46 loc) · 1.24 KB
/
Solution.java
File metadata and controls
57 lines (46 loc) · 1.24 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
package dev.idion.programmers.featuredevelop;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
public class Solution {
public int[] solution(int[] progresses, int[] speeds) {
List<Integer> answerList = new ArrayList<>();
Queue<Task> taskQueue = new LinkedList<>();
for (int i = 0; i < progresses.length; i++) {
taskQueue.add(new Task(progresses[i], speeds[i]));
}
while (!taskQueue.isEmpty()) {
for (Task task : taskQueue) {
task.increaseProgress();
}
int tmp = 0;
while (!taskQueue.isEmpty() && taskQueue.peek().isCompleted()) {
taskQueue.poll();
tmp++;
}
if (tmp != 0) {
answerList.add(tmp);
}
}
int[] answer = new int[answerList.size()];
for (int i = 0; i < answer.length; i++) {
answer[i] = answerList.get(i);
}
return answer;
}
static class Task {
private int progress;
private final int speed;
public Task(int progress, int speed) {
this.progress = progress;
this.speed = speed;
}
public boolean isCompleted() {
return progress > 99;
}
public void increaseProgress() {
this.progress += this.speed;
}
}
}