문제 풀이 코드
function solution(progresses, speeds) {
var answer = [];
var count = 0;
var time = 0; // #1
while(progresses.length > 0){
if ((progresses[0] + speeds[0] * time) >= 100 ){ // #2
count += 1;
progresses.splice(0,1);
speeds.splice(0,1);
time -= 1; // #3
} else {
if (count > 0){
answer.push(count); // #4
count = 0;
}
}
time += 1;
}
answer.push(count);
return answer;
}
FIFO 구조에서 착안해서 코딩했다.
#1
하루가 지날때 마다 시간을 기록하는 변수
#2
진행도 + 작업 속도 X 시간
이 100보다 크면 count += 1
#3
같은 날에 이미 끝난 작업을 체크하기 위해 time -= 1
#4
더이상 끝난 다음 작업이 없으면 answer에 push 함
'코딩테스트' 카테고리의 다른 글
[코딩테스트] 프로그래머스 프린터 with Python (0) | 2021.05.10 |
---|---|
[코딩테스트] 프로그래머스 다리를 지나는 트럭 with Python (0) | 2021.05.09 |
[코딩테스트] 프로그래머스 체육복 with javascript (0) | 2021.05.06 |
[코딩테스트] 프로그래머스 베스트앨범 with javascript (0) | 2021.05.06 |
[코딩테스트] 프로그래머스 위장 with javascript (0) | 2021.05.06 |