728x90
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) {
List<Integer> list = new ArrayList<>();
int i = 0;
while(i<progresses.length){
int distributionNum = 1;
// int requiredDays = (100-progress[i])/speeds[i];
// requiredDays = ((100-progress[i])%speeds[i]==0)? requiredDays:requiredDays+1;
int standardRequiredDays = requiredDays(progresses[i], speeds[i]);
i++;
for( ; i<progresses.length; i++){
if(requiredDays(progresses[i], speeds[i]) > standardRequiredDays){
break;
}
distributionNum++;
}
list.add(distributionNum);
// System.out.println(distributionNum);
}
// list.forEach(System.out::println);
// int[] answer = list.stream().mapToInt(integer->integer.intValue()).toArray();
int[] answer = listToArray(list);
return answer;
}
public int requiredDays(int progress, int speed){
int requiredDays = (100-progress)/speed;
requiredDays = ((100-progress)%speed==0)? requiredDays:requiredDays+1;
return requiredDays;
}
public int[] listToArray(List<Integer> list){
int[] ret = new int[list.size()];
for(int i=0; i<list.size(); i++){
ret[i] = list.get(i);
}
return ret;
}
}
|
cs |
|
|
'알고리즘 풀이 > 프로그래머스' 카테고리의 다른 글
[프로그래머스][JAVA] 짝 지어 제거하기 (스택) (0) | 2022.03.17 |
---|---|
[프로그래머스][JAVA] 타겟넘버 (DFS) (0) | 2022.03.17 |
2 ★ [프로그래머스][JAVA] 124 나라의 숫자 (수학) (0) | 2022.02.27 |
[프로그래머스][JAVA] 멀쩡한 사각형 (수학) (0) | 2022.02.27 |
[프로그래머스][JAVA] 문자열 압축 (문자열) (0) | 2022.02.23 |