Today’s problem
2942. Find Words Containing Character
Intuition
Do what the question ask.
Approach
Do what the question ask, find the string in every word in words array.
Complexity
- Time complexity: $O(N \times M)$, N is the length of words array, M is the length of each word.
- Space complexity: $O(N \times M)$, N is the length of words array, M is the length of each word.
Code
class Solution:
def findWordsContaining(self, words: List[str], x: str) -> List[int]:
ans = []
for i, word in enumerate(words):
if x in word:
ans.append(i)
return ans

Advertisement
For more solutions, please visit My blog