Skip to main content
Back to problems
#2942
Easy Algorithms

Find words containing character

Array String
90.4% acceptance
Feb 25, 2026
690
54
You are given a 0-indexed array of strings words and a character x. Return an array of indices representing the words that contain the character x. Note that the returned array may be in any order.

Solution

Rust
Time O(n)
Space O(1)
LeetCode
solution.rs
impl Solution {
  pub fn find_words_containing(words: Vec<String>, x: char) -> Vec<i32> {
    words
      .iter()
      .enumerate()
      .filter(|(_, w)| w.contains(x))
      .map(|(i, _)| i as i32)
      .collect()
  }
}