LeetCode 1207. Unique Number of Occurrences

Problem Statement


impl Solution {
pub fn unique_occurrences(arr: Vec<i32>) -> bool {
use std::collections::{HashMap, HashSet};

let (mut map, mut set) = (HashMap::new(), HashSet::new());
for i in arr {
*(map.entry(i).or_insert(0)) += 1;
}

for (_, val) in map {
if set.contains(&val) {
return false;
}
set.insert(val);
}
return true;
}
}