✨ 문제 ✨

✨ 정답 ✨
function solution(bridge_length, weight, truck_weights) {
let answer = 0;
let bridge = new Array(bridge_length).fill(0);
let totalWeight = 0;
let idx = 0;
while (bridge.length) {
answer+=1;
const passedTruck = bridge.shift();
totalWeight -= passedTruck;
if (idx < truck_weights.length) {
if (totalWeight + truck_weights[idx] <= weight) {
bridge.push(truck_weights[idx]);
totalWeight += truck_weights[idx];
idx++;
} else {
bridge.push(0);
}
}
}
return answer;
}
🧵 참고한 정답지 🧵
💡💡 기억해야 할 점 💡💡