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
|
||||
Loading…
Add table
Add a link
Reference in a new issue