Skip to content

Commit 9575bb5

Browse files
committed
Runtime: 310 ms (Top 33.33%) | Memory: 85.8 MB (Top 33.33%)
1 parent 23b15a6 commit 9575bb5

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Runtime: 310 ms (Top 33.33%) | Memory: 85.8 MB (Top 33.33%)
2+
13
/**
24
* @param {number[][]} boxes
35
* @param {number} portsCount
@@ -6,24 +8,24 @@
68
* @return {number}
79
*/
810
var boxDelivering = function(boxes, portsCount, maxBoxes, maxWeight) {
9-
11+
1012
const trips = Array(boxes.length + 1).fill(0);
1113
let left = 0;
1214
let diff = 0;
13-
15+
1416
for (let right = 0; right < boxes.length; right++) {
1517
maxBoxes--;
1618
maxWeight -= boxes[right][1];
1719
if (right > 0 && boxes[right][0] !== boxes[right - 1][0]) diff++;
18-
20+
1921
while (maxBoxes < 0 || maxWeight < 0 || (left < right && trips[left + 1] === trips[left])) {
2022
maxBoxes++;
2123
maxWeight += boxes[left++][1];
2224
if (boxes[left][0] !== boxes[left - 1][0]) diff--;
2325
}
24-
26+
2527
trips[right + 1] = diff + 2 + trips[left];
2628
}
27-
29+
2830
return trips[boxes.length];
29-
};
31+
};

0 commit comments

Comments
 (0)