From 8e04e9256b151c84a6df6b351b9e660332a2a6f8 Mon Sep 17 00:00:00 2001 From: jackfiled Date: Thu, 19 Dec 2024 15:07:33 +0800 Subject: [PATCH] 20241219 finished. --- src/problem/mod.rs | 2 + .../p3285_find_indices_of_stable_mountains.rs | 39 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/problem/p3285_find_indices_of_stable_mountains.rs diff --git a/src/problem/mod.rs b/src/problem/mod.rs index 3a2f8ef..4c2789d 100644 --- a/src/problem/mod.rs +++ b/src/problem/mod.rs @@ -378,3 +378,5 @@ mod p1847_closest_room; mod p3291_minimum_number_of_valid_strings_to_form_target_i; mod p3292_minimum_number_of_valid_strings_to_form_target_ii; + +mod p3285_find_indices_of_stable_mountains; diff --git a/src/problem/p3285_find_indices_of_stable_mountains.rs b/src/problem/p3285_find_indices_of_stable_mountains.rs new file mode 100644 index 0000000..e4e4ecb --- /dev/null +++ b/src/problem/p3285_find_indices_of_stable_mountains.rs @@ -0,0 +1,39 @@ +/** + * [3285] Find Indices of Stable Mountains + */ +pub struct Solution {} + +// submission codes start here + +impl Solution { + pub fn stable_mountains(height: Vec, threshold: i32) -> Vec { + (1..height.len()) + .filter_map(|i| { + if height[i - 1] > threshold { + Some(i as i32) + } else { + None + } + }) + .collect() + } +} + +// submission codes end + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_3285() { + assert_eq!( + vec![3, 4], + Solution::stable_mountains(vec![1, 2, 3, 4, 5], 2) + ); + assert_eq!( + Vec::::new(), + Solution::stable_mountains(vec![10, 1, 10, 1, 10], 10) + ); + } +}