Rust Missing Integer
use std::collections::HashSet;
fn missing_integer(a: &[i64]) -> i64 {
let mut vals: Vec<i64> = a.iter().copied().collect::<HashSet<_>>().into_iter().collect();
vals.sort();
let mut min = 1i64;
for v in vals {
if v > 0 {
if min != v {
break;
}
min += 1;
}
}
min
}
This records the positive numbers that exist, then returns the smallest positive value that is still missing.