728x90
반응형
문제
https://school.programmers.co.kr/learn/courses/30/lessons/42586
결과
나의 풀이
function solution(progresses, speeds) {
var answer = [];
let temp = {};
let key = [];
let standardDay = -1;
for ( let i = 0; i < progresses.length; i++ ) {
let pro = progresses[ i ];
let speed = speeds[ i ];
let needDay = calculate( pro, speed );
if ( standardDay >= needDay ) {
temp[ standardDay ] += 1;
} else {
standardDay = needDay;
key.push( needDay );
temp[ needDay ] = 1;
}
}
key.forEach( k => answer.push( temp[k] ) );
return answer;
}
function calculate( progress, speed ) {
let remain = 100 - progress;
return Math.ceil( remain / speed );
}
728x90
반응형
'Algorithm > Programmers' 카테고리의 다른 글
코딩테스트 연습 > 스택/큐 > 올바른 괄호 - javascript 풀이 (0) | 2022.11.18 |
---|