mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
@ -203,6 +203,26 @@ function uniqueOccurrences(arr: number[]): boolean {
|
||||
```
|
||||
|
||||
|
||||
### 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">
|
||||
|
Reference in New Issue
Block a user