Rust Distinct
use std::collections::HashSet;
fn distinct(a: &[i64]) -> i64 {
let set: HashSet<_> = a.iter().collect();
set.len() as i64
}
This counts unique values by tracking what has already been seen.
use std::collections::HashSet;
fn distinct(a: &[i64]) -> i64 {
let set: HashSet<_> = a.iter().collect();
set.len() as i64
}
This counts unique values by tracking what has already been seen.