-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmissing_integer.rs
More file actions
35 lines (28 loc) · 782 Bytes
/
Copy pathmissing_integer.rs
File metadata and controls
35 lines (28 loc) · 782 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
struct MissingInteger;
impl MissingInteger {
fn solution(&self, a: &Vec<i32>) -> u32 {
let mut test_arr = vec![false; 1_000_000_001];
for e in a {
if *e > 0 {
test_arr[*e as usize] = true;
}
}
for (i, c) in test_arr.into_iter().enumerate() {
if i > 0 && !c {
return i as u32;
}
}
0
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_max_counters() {
let max_counters = MissingInteger;
assert_eq!(max_counters.solution(vec![1, 3, 6, 4, 1, 2].as_ref()), 5);
assert_eq!(max_counters.solution(vec![1, 2, 3].as_ref()), 4);
assert_eq!(max_counters.solution(vec![-1, -3].as_ref()), 1);
}
}