feat: 1207.独一无二的出现次数,新增rust解法

This commit is contained in:
junjie2.luo
2024-10-10 17:18:04 +08:00
parent dbc93eb196
commit baf7ed122b

View File

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