Skip to content

Commit 50e089a

Browse files
authored
Create 1710-maximum-units-on-a-truck.js
1 parent ee781a8 commit 50e089a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

1710-maximum-units-on-a-truck.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @param {number[][]} boxTypes
3+
* @param {number} truckSize
4+
* @return {number}
5+
*/
6+
const maximumUnits = function (boxTypes, truckSize) {
7+
boxTypes.sort((a, b) => b[1] - a[1])
8+
let res = 0
9+
10+
for (let i = 0; i < boxTypes.length && truckSize > 0; ++i) {
11+
let used = Math.min(boxTypes[i][0], truckSize)
12+
truckSize -= used
13+
res += used * boxTypes[i][1]
14+
}
15+
return res
16+
}

0 commit comments

Comments
 (0)