We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b099b3d commit 953320fCopy full SHA for 953320f
1 file changed
이용훈/8주차/260219.js
@@ -0,0 +1,27 @@
1
+function solution(bridge_length, weight, truck_weights) {
2
+ let sum = 0;
3
+ let answer = 0;
4
+
5
+ const bridge = Array(bridge_length).fill(0);
6
+ while(truck_weights.length || sum > 0) {
7
+ answer++;
8
9
+ const cur = bridge.shift();
10
+ sum -= cur;
11
12
+ if(truck_weights.length) {
13
+ const next = truck_weights[0]
14
+ if(sum + next <= weight) {
15
+ bridge.push(next);
16
+ sum += next;
17
+ truck_weights.shift();
18
+ } else {
19
+ bridge.push(0);
20
+ }
21
22
23
24
25
26
+ return answer;
27
+}
0 commit comments