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.
2 parents 46aaf50 + f9c0bdc commit c8d9e51Copy full SHA for c8d9e51
suyeun84/202509/07 PGM LV2 다리를 지나는 트럭.md
@@ -0,0 +1,37 @@
1
+```java
2
+import java.util.*;
3
+
4
+class Solution {
5
+ public int solution(int bridge_length, int weight, int[] truck_weights) {
6
+ Queue q = new LinkedList();
7
8
+ for(int i=0;i<bridge_length-1;i++){
9
+ q.add(0);
10
+ }
11
12
+ int current_w = truck_weights[0];
13
+ q.add(current_w);
14
15
+ int answer = 1;
16
+ int index = 1;
17
18
+ while(!q.isEmpty()){
19
+ answer++;
20
21
+ int removed = (int) q.poll();
22
+ current_w -= removed;
23
24
+ if(index < truck_weights.length){
25
+ if(current_w + truck_weights[index] <= weight){
26
+ current_w += truck_weights[index];
27
+ q.add(truck_weights[index]);
28
+ index++;
29
+ }else{
30
31
32
33
34
+ return answer;
35
36
+}
37
+```
0 commit comments