|
| 1 | +You are given a 0-indexed array of strings words and a character x. |
| 2 | + |
| 3 | +Return an array of indices representing the words that contain the character x. |
| 4 | + |
| 5 | +Note that the returned array may be in any order. |
| 6 | +----------------------------------------------------------------------------------------- |
| 7 | + |
| 8 | +class Solution: |
| 9 | + def findWordsContaining(self, words: List[str], x: str) -> List[int]: |
| 10 | + res = [] |
| 11 | + for ind,word in enumerate(words): |
| 12 | + if x in word: |
| 13 | + res.append(ind) |
| 14 | + |
| 15 | + return res |
| 16 | +--------------------------------------------------------------------------------------------------- |
| 17 | + |
| 18 | +class Solution: |
| 19 | + def findWordsContaining(self, words: List[str], x: str) -> List[int]: |
| 20 | + return [i for i, w in enumerate(words) if w.find(x)!=-1] |
| 21 | + |
| 22 | + |
0 commit comments