添加 1207 独一无二的出现次数 Go 版本

This commit is contained in:
Wang Ben
2023-07-19 17:41:44 +08:00
parent ca85e56bc7
commit 1a2c911194

View File

@ -135,6 +135,22 @@ class Solution:
Go
```Go
func uniqueOccurrences(arr []int) bool {
count := make(map[int]int) // 统计数字出现的频率
for _, v := range arr {
count[v] += 1
}
fre := make(map[int]struct{}) // 看相同频率是否重复出现
for _, v := range count {
if _, ok := fre[v]; ok {
return false
}
fre[v] = struct{}{}
}
return true
}
```
JavaScript
``` javascript