20241219 finished.
This commit is contained in:
parent
8798fc1596
commit
8e04e9256b
|
@ -378,3 +378,5 @@ mod p1847_closest_room;
|
||||||
mod p3291_minimum_number_of_valid_strings_to_form_target_i;
|
mod p3291_minimum_number_of_valid_strings_to_form_target_i;
|
||||||
|
|
||||||
mod p3292_minimum_number_of_valid_strings_to_form_target_ii;
|
mod p3292_minimum_number_of_valid_strings_to_form_target_ii;
|
||||||
|
|
||||||
|
mod p3285_find_indices_of_stable_mountains;
|
||||||
|
|
39
src/problem/p3285_find_indices_of_stable_mountains.rs
Normal file
39
src/problem/p3285_find_indices_of_stable_mountains.rs
Normal 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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user