https://programmers.co.kr/learn/courses/30/lessons/42583
function solution(bridge_length, weight, truck_weights) {
var answer = 0;
var q = [];
var qs = [];
var s = 0;
var cnt = 0;
var qweight = 0;
while (1) {
s++;
if (cnt == truck_weights.length && q.length == 0) {
break;
}
if (qweight + truck_weights[cnt] <= weight) {
q.push(truck_weights[cnt]);
qs.push(0);
qweight += truck_weights[cnt];
cnt++;
}
for (var i = 0; i < qs.length; i++) {
qs[i]++;
}
if (qs[0] == bridge_length) {
qweight -= q.shift();
qs.shift();
}
}
answer = s;
return answer;
}
'algorithm > js' 카테고리의 다른 글
[프로그래머스] 문자열 압축 (0) | 2020.05.01 |
---|---|
[프로그래머스] 기능개발 (0) | 2020.04.30 |
[프로그래머스] 스킬트리 (0) | 2020.04.30 |
[프로그래머스] 124나라의 숫자 (0) | 2020.04.30 |
[프로그래머스] 쇠막대기 (0) | 2020.04.30 |
댓글