#2942

Find Words Containing Character

newbie · 100 · lc easy +12 · verified · 90.4% accepted · 691 likes · top 100%

Description

Given a 0-indexed string array words and a character x, find all indices i such that words[i] contains x.

Return those indices in any order.

Example 1:

Input: words = ["leet","code"], x = "e"
Output: [0,1]
Explanation: "e" occurs in both words: "leet", and "code". Hence, we return indices 0 and 1.

Example 2:

Input: words = ["abc","bcd","aaaa","cbc"], x = "a"
Output: [0,2]
Explanation: "a" occurs in "abc", and "aaaa". Hence, we return indices 0 and 2.

Example 3:

Input: words = ["abc","bcd","aaaa","cbc"], x = "z"
Output: []
Explanation: "z" does not occur in any of the words. Hence, we return an empty array.

Code

1
2
3