코딩테스트 문제풀이/프로그래머스
[프로그래머스] 고득점 Kit 스택/큐 문제풀이
itaeiou
2022. 3. 13. 21:12
반응형
42586 기능개발
https://programmers.co.kr/learn/courses/30/lessons/42586
20220313 javascript 풀이
function solution(progresses, speeds) {
let answer = [];
let release = 0;
let count = 0;
progresses.forEach((v, i) => {
let day = Math.ceil( (100-v)/speeds[i] );
if(count>0 && release < day) {
answer.push(count);
count = 0;
}
if(count === 0) {
release = day;
}
count++;
})
answer.push(count);
return answer;
}
function solution(progresses, speeds) {
let answer = [];
let release = [];
progresses.forEach((v, i) => {
let day = Math.ceil( (100-v)/speeds[i] );
if(release.length === 0) {
release.push(day);
} else {
if(release[0] >= day) {
release.push(day);
} else {
answer.push(release.length);
release = [day];
}
}
})
answer.push(release.length);
return answer;
}
42583 다리를 지나는 트럭
https://programmers.co.kr/learn/courses/30/lessons/42583
20220329 javascript 풀이
function solution(bridge_length, weight, truck_weights) {
let time = 0;
let queue = [[bridge_length, truck_weights[0]]];
let sum_weight = truck_weights[0];
let i = 1;
while(queue.length > 0) {
if(queue[0][0] <= time) {
sum_weight -= queue[0][1];
queue.shift();
}
if(sum_weight + truck_weights[i] <= weight) {
sum_weight += truck_weights[i];
queue.push([time+bridge_length, truck_weights[i]]);
i++;
}
time++;
}
return time;
}
반응형