Skip to content

Commit ada3d37

Browse files
authored
Update 1564-put-boxes-into-the-warehouse-i.js
1 parent 1e05a21 commit ada3d37

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

1564-put-boxes-into-the-warehouse-i.js

+21
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,24 @@ const maxBoxesInWarehouse = function(boxes, warehouse) {
1515
}
1616
return j
1717
};
18+
19+
// another
20+
21+
/**
22+
* @param {number[]} boxes
23+
* @param {number[]} warehouse
24+
* @return {number}
25+
*/
26+
const maxBoxesInWarehouse = function(boxes, warehouse) {
27+
if(warehouse == null || warehouse.length === 0) return 0
28+
const m = boxes.length, n = warehouse.length
29+
for(let i = 1; i < n; i++) {
30+
warehouse[i] = Math.min(warehouse[i], warehouse[i - 1])
31+
}
32+
boxes.sort((a, b) => a - b)
33+
let res = 0
34+
for(let i = n - 1; i >= 0; i--) {
35+
if(res < m && boxes[res] <= warehouse[i]) res++
36+
}
37+
return res
38+
};

0 commit comments

Comments
 (0)