-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
51 lines (38 loc) · 1.22 KB
/
Solution.java
File metadata and controls
51 lines (38 loc) · 1.22 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
import java.util.List;
import java.util.ArrayList;
import java.util.Queue;
import java.util.LinkedList;
public class Solution {
public static void main(String[] args){
int[] progresses = {93,30,55};
int[] speeds = {1,30,5};
int[] answer = solution(progresses, speeds);
for(int num : answer){
System.out.print(num + " ");
}
}
public static int[] solution(int[] progresses, int[] speeds){
Queue<Integer> periods = new LinkedList<Integer>();
for(int i=0; i<progresses.length; i++){
int day = (100-progresses[i])/speeds[i];
int period = (100-progresses[i])%speeds[i] == 0 ? day : day + 1;
periods.add(period);
}
List<Integer> result = new ArrayList<Integer>();
while(!periods.isEmpty()){
int period = periods.poll();
int cnt = 1;
while(!periods.isEmpty() && period >= periods.peek()){
periods.poll();
cnt++;
}
result.add(cnt);
}
int[] answer = new int[result.size()];
int idx = 0;
for(int num : result){
answer[idx++] = num;
}
return answer;
}
}