2942. Find Words Containing Character Easy

@problem@discussion
#Array#String



1/**
2 * [2942] Find Words Containing Character
3 *
4 * You are given a 0-indexed array of strings words and a character x.
5 * Return an array of indices representing the words that contain the character x.
6 * Note that the returned array may be in any order.
7 *  
8 * <strong class="example">Example 1:
9 * 
10 * Input: words = ["leet","code"], x = "e"
11 * Output: [0,1]
12 * Explanation: "e" occurs in both words: "l<u>ee</u>t", and "cod<u>e</u>". Hence, we return indices 0 and 1.
13 * 
14 * <strong class="example">Example 2:
15 * 
16 * Input: words = ["abc","bcd","aaaa","cbc"], x = "a"
17 * Output: [0,2]
18 * Explanation: "a" occurs in "<u>a</u>bc", and "<u>aaaa</u>". Hence, we return indices 0 and 2.
19 * 
20 * <strong class="example">Example 3:
21 * 
22 * Input: words = ["abc","bcd","aaaa","cbc"], x = "z"
23 * Output: []
24 * Explanation: "z" does not occur in any of the words. Hence, we return an empty array.
25 * 
26 *  
27 * Constraints:
28 * 
29 * 	1 <= words.length <= 50
30 * 	1 <= words[i].length <= 50
31 * 	x is a lowercase English letter.
32 * 	words[i] consists only of lowercase English letters.
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/find-words-containing-character/
38// discuss: https://leetcode.com/problems/find-words-containing-character/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn find_words_containing(words: Vec<String>, x: char) -> Vec<i32> {
44        vec![]
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_2942() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.