deno.land / x / masx200_leetcode_test@10.6.5 / maximum-equal-frequency / index.go

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
package index
func maxEqualFreq(nums []int) (ans int) { freq := map[int]int{} count := map[int]int{} maxFreq := 0 for i, num := range nums { if count[num] > 0 { freq[count[num]]-- } count[num]++ maxFreq = max(maxFreq, count[num]) freq[count[num]]++ if maxFreq == 1 || freq[maxFreq]*maxFreq+freq[maxFreq-1]*(maxFreq-1) == i+1 && freq[maxFreq] == 1 || freq[maxFreq]*maxFreq+1 == i+1 && freq[1] == 1 { ans = max(ans, i+1) } } return}
func max(a, b int) int { if b > a { return b } return a}
masx200_leetcode_test

Version Info

Tagged at
a year ago