Skip to content

Commit

Permalink
Merge pull request youngyangyang04#2192 from wangben18/master
Browse files Browse the repository at this point in the history
添加 1207 独一无二的出现次数 Go 版本
  • Loading branch information
youngyangyang04 committed Aug 3, 2023
2 parents 197d6c5 + f08eaaa commit 13888a5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions problems/1207.独一无二的出现次数.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,30 @@ function uniqueOccurrences(arr: number[]): boolean {
})
return countMap.size === new Set(countMap.values()).size;
};
```


### 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
}
```




<p align="center">
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
Expand Down

0 comments on commit 13888a5

Please sign in to comment.