/
iterative.rs
45 lines (38 loc) · 1.2 KB
/
iterative.rs
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
36
37
38
39
40
41
42
43
44
45
pub struct Solution;
// ------------------------------------------------------ snip ------------------------------------------------------ //
impl Solution {
pub fn three_consecutive_odds(arr: Vec<i32>) -> bool {
let mut iter = arr.iter().map(|&x| x & 1 != 0);
while let Some(is_odd) = iter.next() {
if is_odd {
if let Some(is_odd) = iter.next() {
if is_odd {
if let Some(is_odd) = iter.next() {
if is_odd {
return true;
}
} else {
break;
}
}
} else {
break;
}
}
}
false
}
}
// ------------------------------------------------------ snip ------------------------------------------------------ //
impl super::Solution for Solution {
fn three_consecutive_odds(arr: Vec<i32>) -> bool {
Self::three_consecutive_odds(arr)
}
}
#[cfg(test)]
mod tests {
#[test]
fn test_solution() {
super::super::tests::run::<super::Solution>();
}
}