Skip to content

Commit 526e491

Browse files
authored
Merge pull request #1370 from AlgorithmWithGod/ksinji
[20251110] PGM / LV2 / 다리를 지나는 트럭 / 강신지
2 parents 4125430 + 00358b2 commit 526e491

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(int bridge_length, int weight, int[] truck_weights) {
6+
int answer = 0;
7+
8+
Queue<Integer> bridge = new ArrayDeque<>();
9+
for (int i = 0; i < bridge_length; i++) {
10+
bridge.add(0);
11+
}
12+
13+
int idx = 0;
14+
int sum = 0;
15+
16+
while(idx < truck_weights.length){
17+
answer++;
18+
sum -= bridge.poll();
19+
20+
if (sum+truck_weights[idx] > weight){
21+
bridge.add(0);
22+
continue;
23+
}
24+
25+
bridge.add(truck_weights[idx]);
26+
sum += truck_weights[idx++];
27+
}
28+
return answer+bridge_length;
29+
}
30+
}
31+
```

0 commit comments

Comments
 (0)