네카라쿠배 취준반 - 프로그래머스 문제 풀이/코딩 테스트 연습 - 해시
[프로그래머스] 기능개발 문제 풀이(Queue 큐 Lv. 2) - java 자바
개발자로 취직하기
2022. 5. 24. 21:16
0. 자세한 설명은 YouTube 영상으로
1. ArrayList + for 문을 활용한 Solution
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
List<Integer> answer = new ArrayList<Integer>();
for (int i = 0; i < progresses.length; i++) {
// 1. 한 개 기능을 개발하는데 필요한 날짜 계산
double days = (100 - progresses[i]) / (double) speeds[i];
int daysUp = (int) Math.ceil(days);
// 2. 함께 배포할 기능의 index 찾기
int j = i + 1;
for (; j < progresses.length; j++)
if (progresses[j] + daysUp * speeds[j] < 100)
break;
// 3. 이번에 배포할 기능의 개수를 추가하기
answer.add(j - i);
i = j - 1;
}
// 4. ArrayList를 array 형태로 변경하여 반환
return answer.stream().mapToInt(i -> i.intValue()).toArray();
}
}