aboutsummaryrefslogtreecommitdiff
path: root/find_words_contain_char.py
blob: 5554b2f7d469a7ea6f3f204563274439941011c4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 2942. Find Words Containing Character

"""
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.
"""


class Solution(object):
    def findWordsContaining(self, words, x):
        """
        :type words: List[str]
        :type x: str
        :rtype: List[int]
        """
        return [i for i in range(len(words)) if x in words[i]]


if __name__ == "__main__":
    obj = Solution()
    print(obj.findWordsContaining(words=["leet", "code"], x="e"))
    print(obj.findWordsContaining(words=["abc", "bcd", "aaaa", "cbc"], x="a"))
    print(obj.findWordsContaining(words=["abc", "bcd", "aaaa", "cbc"], x="z"))