-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolution3074.go
More file actions
40 lines (32 loc) · 860 Bytes
/
Copy pathsolution3074.go
File metadata and controls
40 lines (32 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package solution3074
import (
"slices"
)
// ============================================================================
// 3074. Apple Redistribution into Boxes
// URL: https://leetcode.com/problems/apple-redistribution-into-boxes/
// ============================================================================
/*
goos: linux
goarch: amd64
pkg: GoLeetCode/solutions/3074---Apple-Redistribution-into-Boxes
cpu: 13th Gen Intel(R) Core(TM) i7-13700K
Benchmark_minimumBoxes
Benchmark_minimumBoxes-24 124226916 14.35 ns/op 0 B/op 0 allocs/op
PASS
*/
func minimumBoxes(apple []int, capacity []int) int {
slices.Sort(capacity)
apples := 0
for i := 0; i < len(apple); i++ {
apples += apple[i]
}
i := len(capacity) - 1
boxes := 0
for i >= 0 && apples > 0 {
apples -= capacity[i]
boxes++
i--
}
return boxes
}