20241219 finished.

This commit is contained in:
jackfiled 2024-12-19 15:07:33 +08:00
parent 8798fc1596
commit 8e04e9256b
2 changed files with 41 additions and 0 deletions

View File

@ -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;

View File

@ -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<i32>, threshold: i32) -> Vec<i32> {
(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::<i32>::new(),
Solution::stable_mountains(vec![10, 1, 10, 1, 10], 10)
);
}
}