This commit is contained in:
2025-09-23 01:56:29 +08:00
parent 3f58f483ff
commit f94834d397
3 changed files with 83 additions and 0 deletions

28
25/09/3005.go Normal file
View File

@@ -0,0 +1,28 @@
package main
import (
"fmt"
)
func maxFrequencyElements(nums []int) int {
m := make(map[int]int)
ans := 0
max := 0
for _, x := range nums {
m[x]++
c := m[x]
if c > max {
max = c
ans = c
} else if c == max {
ans += c
}
}
return ans
}
func main() {
// 示例测试
nums := []int{1, 2, 2, 3, 1, 4}
fmt.Println(maxFrequencyElements(nums)) // 输出: 4
}