Skip to content

Commit b7ed6ef

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

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
@@ -36,3 +36,24 @@ const maxBoxesInWarehouse = function(boxes, warehouse) {
3636
}
3737
return res
3838
};
39+
40+
// another
41+
42+
/**
43+
* @param {number[]} boxes
44+
* @param {number[]} warehouse
45+
* @return {number}
46+
*/
47+
const maxBoxesInWarehouse = function(boxes, warehouse) {
48+
if(warehouse == null || warehouse.length === 0) return 0
49+
const m = boxes.length, n = warehouse.length
50+
boxes.sort((a, b) => a - b)
51+
let i = m - 1, res = 0
52+
for(let house of warehouse) {
53+
while(i >= 0 && boxes[i] > house) i--
54+
if(i === -1) return res
55+
res++
56+
i--
57+
}
58+
return res
59+
};

0 commit comments

Comments
 (0)