mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
feat: 1207.独一无二的出现次数,新增rust解法
This commit is contained in:
@ -221,6 +221,28 @@ func uniqueOccurrences(arr []int) bool {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Rust
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
|
impl Solution {
|
||||||
|
pub fn unique_occurrences(arr: Vec<i32>) -> bool {
|
||||||
|
let mut hash = HashMap::<i32, i32>::new();
|
||||||
|
for x in arr {
|
||||||
|
*hash.entry(x).or_insert(0) += 1;
|
||||||
|
}
|
||||||
|
let mut set = HashSet::<i32>::new();
|
||||||
|
for (_k, v) in hash {
|
||||||
|
if set.contains(&v) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
set.insert(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user