20250524 finished.
This commit is contained in:
parent
11ef8edf9d
commit
993535a05b
|
@ -672,3 +672,5 @@ mod p3356_zero_array_transformation_ii;
|
|||
mod p3362_zero_array_transformation_iii;
|
||||
|
||||
mod p3068_find_the_maximum_sum_of_node_values;
|
||||
|
||||
mod p2942_find_words_containing_character;
|
||||
|
|
39
src/problem/p2942_find_words_containing_character.rs
Normal file
39
src/problem/p2942_find_words_containing_character.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* [2942] Find Words Containing Character
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn find_words_containing(words: Vec<String>, x: char) -> Vec<i32> {
|
||||
words
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter_map(|(i, v)| if v.contains(x) { Some(i as i32) } else { None })
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_2942() {
|
||||
assert_eq!(
|
||||
vec![0, 1],
|
||||
Solution::find_words_containing(vec_string!("leet", "code"), 'e')
|
||||
);
|
||||
assert_eq!(
|
||||
vec![0, 2],
|
||||
Solution::find_words_containing(vec_string!("abc", "bcd", "aaaa", "cbc"), 'a')
|
||||
);
|
||||
assert_eq!(
|
||||
Vec::<i32>::new(),
|
||||
Solution::find_words_containing(vec_string!("abc", "bcd", "aaaa", "cbc"), 'z'),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user