We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ddfe102 commit 00358b2Copy full SHA for 00358b2
ksinji/202511/10 PGM 다리를 지나는 트럭.md
@@ -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
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