1
0

3005.go 382 B

12345678910111213141516171819202122232425262728
  1. package main
  2. import (
  3. "fmt"
  4. )
  5. func maxFrequencyElements(nums []int) int {
  6. m := make(map[int]int)
  7. ans := 0
  8. max := 0
  9. for _, x := range nums {
  10. m[x]++
  11. c := m[x]
  12. if c > max {
  13. max = c
  14. ans = c
  15. } else if c == max {
  16. ans += c
  17. }
  18. }
  19. return ans
  20. }
  21. func main() {
  22. // 示例测试
  23. nums := []int{1, 2, 2, 3, 1, 4}
  24. fmt.Println(maxFrequencyElements(nums)) // 输出: 4
  25. }
备用站点 当前处于降级运行的备用站点,仅供应急访问,数据和功能可能不是最新。