예전에 코플릿에서 본 적이 있는 듯한 문제라서 빠르게 풀렸음..
function solution(progresses, speeds) {
const result = [];
while(progresses.length > 0){
let count = 0;
for(let i = 0 ; i < progresses.length ; i++){
progresses[i] += speeds[i];
}
while(progresses[0] >= 100){
progresses.shift();
speeds.shift();
count++;
}
if(count !== 0){
result.push(count);
}
}
return result;
}
코플릿에서도 프린터도 있었지만, 다른 문제였다
반복문 안에서 Math.max()를 썼으니 O(n^2)인가?
사실 while문이 O(n)이상 돌 수도 있으니 그 이상인 듯함
function solution(priorities, location) {
let count = 0;
while(location >= 0){
const head = priorities.shift();
location--;
const max = Math.max(...priorities);
if(max > head){
priorities.push(head);
if(location < 0){
location = priorities.length-1
}
} else {
count++;
}
}
return count;
}