#1967
Easy Algorithms Number of strings that appear as substrings in word
Array String
82.4% acceptance
Feb 25, 2026
756
42
Given an array of strings patterns and a string word, return the number of strings in patterns that exist as a substring in word.
A substring is a contiguous sequence of characters within a string.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn num_of_strings(patterns: Vec<String>, word: String) -> i32 {
patterns.iter().filter(|p| word.contains(p.as_str())).count() as i32
}
}