20250511 finished.
This commit is contained in:
parent
62515ef741
commit
ebc48df001
|
@ -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;
|
||||
|
|
42
src/problem/p1550_three_consecutive_odds.rs
Normal file
42
src/problem/p1550_three_consecutive_odds.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
* [1550] Three Consecutive Odds
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn three_consecutive_odds(arr: Vec<i32>) -> 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
|
||||
]));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user