add new solutions
This commit is contained in:
parent
ca24d0a56a
commit
0c73608ce5
36 changed files with 791 additions and 0 deletions
27
solutions/30/q3005/solution.go
Normal file
27
solutions/30/q3005/solution.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package q3005
|
||||
|
||||
import "slices"
|
||||
|
||||
func maxFrequencyElements(nums []int) int {
|
||||
slices.Sort(nums)
|
||||
maxFreq := 0
|
||||
nMaxFreq := 0
|
||||
|
||||
freq := 1
|
||||
for i := 1; i <= len(nums); i++ {
|
||||
if i < len(nums) && nums[i] == nums[i-1] {
|
||||
freq++
|
||||
} else {
|
||||
if freq > maxFreq {
|
||||
maxFreq = freq
|
||||
nMaxFreq = 1
|
||||
} else if freq == maxFreq {
|
||||
nMaxFreq++
|
||||
}
|
||||
freq = 1
|
||||
}
|
||||
}
|
||||
return maxFreq * nMaxFreq
|
||||
}
|
||||
|
||||
var _ = maxFrequencyElements
|
||||
21
solutions/30/q3074/solution.go
Normal file
21
solutions/30/q3074/solution.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package q3074
|
||||
|
||||
import "slices"
|
||||
|
||||
func minimumBoxes(apple []int, capacity []int) int {
|
||||
apples := 0
|
||||
for _, a := range apple {
|
||||
apples += a
|
||||
}
|
||||
|
||||
slices.Sort(capacity)
|
||||
for i := len(capacity) - 1; i >= 0; i-- {
|
||||
apples -= capacity[i]
|
||||
if apples <= 0 {
|
||||
return len(capacity) - i
|
||||
}
|
||||
}
|
||||
return len(capacity)
|
||||
}
|
||||
|
||||
var _ = minimumBoxes
|
||||
Loading…
Add table
Add a link
Reference in a new issue