1234567891011121314151617181920 |
- use std::collections::HashMap;
-
- pub fn unique_occurrences(arr: Vec<i32>) -> bool {
- let mut hm = HashMap::<i32, i32>::new();
- for n in arr {
- let count = hm.entry(n).or_insert(0);
- *count += 1;
- }
- let mut vals: Vec<&i32> = hm.values().collect();
- vals.sort();
- let og_length = vals.len();
- vals.dedup_by_key(|i| *i);
- let new_length = vals.len();
- og_length == new_length
- }
-
- pub fn main() {
- println!("Expected: true");
- println!("Got: {}", unique_occurrences(vec![1, 2, 2, 3, 3, 3]));
- }
|