aboutsummaryrefslogtreecommitdiff
path: root/find_words_contain_char.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2025-05-23 18:42:20 -0600
committerJack Sangdahl <[email protected]>2025-05-23 18:42:20 -0600
commit3511e79e0d439127357bf34bd8d5b726a9092028 (patch)
tree00f6e620992f4b7f05296429edcb3c5136814d67 /find_words_contain_char.py
parent7c308860a1d9db2d811d89141550010378d19405 (diff)
downloadleetcode-3511e79e0d439127357bf34bd8d5b726a9092028.tar.gz
leetcode-3511e79e0d439127357bf34bd8d5b726a9092028.zip
2942. find words containing character
Diffstat (limited to 'find_words_contain_char.py')
-rw-r--r--find_words_contain_char.py24
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"))