이번문제는 queue에다가 기능개발에 소요되는 각각의 기능들의 소요일수를 저장 해 놓고 하나씩 빼보며 몇개를 연속으로 뺄 수 있나 체크하고 기록하여 출력하였다.
import java.util.*;
class Solution {
public int[] solution(int[] progresses, int[] speeds) {
List<Integer> resultList = new ArrayList<>();
int max = -1000, memory = 0;
Queue<Integer> q = new ArrayDeque<>();
for(int i = 0 ; i < progresses.length ; i++ ){
if((100 - progresses[i]) % speeds[i] == 0)
q.add((100 - progresses[i]) / speeds[i]);
else
q.add((100 - progresses[i]) / speeds[i] + 1);
}
while(!q.isEmpty()){
if(max >= q.peek()){
memory += 1;
q.poll();
}
else{
if(memory != 0){
resultList.add(memory);
memory = 0;
}
max = q.peek();
memory = 1;
q.poll();
}
}
resultList.add(memory);
int[] answer = new int[resultList.size()];
for(int i = 0; i < resultList.size(); i++) {
answer[i] = resultList.get(i);
}
return answer;
}
}
'Algorithm > Programers' 카테고리의 다른 글
Lv 2. 프로세스 (0) | 2024.06.14 |
---|---|
Lv 2. 튜플 (0) | 2024.06.13 |
Lv 2. 1차 캐시 (0) | 2024.06.02 |
Lv 2. pH-index (0) | 2024.05.30 |
Lv 2. 할인행사 (0) | 2024.05.29 |