diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 157580e..39eadbe 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -646,3 +646,5 @@ mod p3342_find_minimum_time_to_reach_last_room_ii; mod p3343_count_number_of_balanced_permutations; mod p2918_minimum_equal_sum_of_two_arrays_after_replacing_zeros; + +mod p1550_three_consecutive_odds; diff --git a/src/problem/p1550_three_consecutive_odds.rs b/src/problem/p1550_three_consecutive_odds.rs new file mode 100644 index 0000000..cf2f88e --- /dev/null +++ b/src/problem/p1550_three_consecutive_odds.rs @@ -0,0 +1,42 @@ +/** + * [1550] Three Consecutive Odds + */ +pub struct Solution {} + +// submission codes start here + +impl Solution { + pub fn three_consecutive_odds(arr: Vec) -> bool { + if arr.len() < 3 { + return false; + } + + arr.iter() + .enumerate() + .skip(2) + .filter_map(|(i, &z)| { + if arr[i - 2] % 2 == 1 && arr[i - 1] % 2 == 1 && z % 2 == 1 { + Some(()) + } else { + None + } + }) + .next() + .is_some() + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_1550() { + assert!(!Solution::three_consecutive_odds(vec![2, 6, 4, 1])); + assert!(Solution::three_consecutive_odds(vec![ + 1, 2, 34, 3, 4, 5, 7, 23, 12 + ])); + } +}