uncommited problems
This commit is contained in:
20
maximum-units-on-a-truck/sol.go
Normal file
20
maximum-units-on-a-truck/sol.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import "sort"
|
||||
|
||||
func maximumUnits(boxTypes [][]int, truckSize int) int {
|
||||
sort.Slice(boxTypes, func(i, j int) bool {
|
||||
return boxTypes[i][1] > boxTypes[j][1]
|
||||
})
|
||||
units := 0
|
||||
count := 0
|
||||
for idx := 0; idx < len(boxTypes); idx++ {
|
||||
units += boxTypes[idx][0] * boxTypes[idx][1]
|
||||
count += boxTypes[idx][0]
|
||||
if count >= truckSize {
|
||||
units -= (count - truckSize) * boxTypes[idx][1]
|
||||
return units
|
||||
}
|
||||
}
|
||||
return units
|
||||
}
|
Reference in New Issue
Block a user