1
0
Fork 0
mirror of https://gitlab.com/mfocko/LeetCode.git synced 2024-11-09 15:59:06 +01:00
LeetCode/rs/unique-number-of-occurrences.rs
Matej Focko cece461197
rs: add “1207. Unique Number of Occurrences”
Signed-off-by: Matej Focko <mfocko@redhat.com>
2024-01-11 23:19:00 +01:00

13 lines
361 B
Rust

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()
}
}