diff options
Diffstat (limited to 'find_words_contain_char.py')
-rw-r--r-- | find_words_contain_char.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/find_words_contain_char.py b/find_words_contain_char.py new file mode 100644 index 0000000..5554b2f --- /dev/null +++ b/find_words_contain_char.py @@ -0,0 +1,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")) |