rs: add “1207. Unique Number of Occurrences”
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
744059e7b1
commit
cece461197
1 changed files with 13 additions and 0 deletions
13
rs/unique-number-of-occurrences.rs
Normal file
13
rs/unique-number-of-occurrences.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
impl Solution {
|
||||
pub fn unique_occurrences(arr: Vec<i32>) -> bool {
|
||||
// count frequencies
|
||||
let mut freqs: HashMap<i32, i32> = HashMap::new();
|
||||
for x in &arr {
|
||||
*freqs.entry(*x).or_insert(0) += 1;
|
||||
}
|
||||
|
||||
freqs.values().collect::<HashSet<_>>().len() == freqs.len()
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue