Skip to content

Commit baf7ed1

Browse files
author
junjie2.luo
committed
feat: 1207.独一无二的出现次数,新增rust解法
1 parent dbc93eb commit baf7ed1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

problems/1207.独一无二的出现次数.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,28 @@ func uniqueOccurrences(arr []int) bool {
221221
}
222222
```
223223

224+
### Rust
225+
226+
```rust
227+
use std::collections::{HashMap, HashSet};
228+
impl Solution {
229+
pub fn unique_occurrences(arr: Vec<i32>) -> bool {
230+
let mut hash = HashMap::<i32, i32>::new();
231+
for x in arr {
232+
*hash.entry(x).or_insert(0) += 1;
233+
}
234+
let mut set = HashSet::<i32>::new();
235+
for (_k, v) in hash {
236+
if set.contains(&v) {
237+
return false
238+
} else {
239+
set.insert(v);
240+
}
241+
}
242+
true
243+
}
244+
}
245+
```
224246

225247

226248

0 commit comments

Comments
 (0)