func majorityElement(nums []int) (ans []int) {
cnt := map[int]int{}
for _, v := range nums {
cnt[v]++
}
for v, c := range cnt {
if c > len(nums)/3 {
ans = append(ans, v)
}
}
return
}
2024-07-12 11:52:51
func majorityElement(nums []int) (ans []int) {
cnt := map[int]int{}
for _, v := range nums {
cnt[v]++
}
for v, c := range cnt {
if c > len(nums)/3 {
ans = append(ans, v)
}
}
return
}