Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5d2e028

Browse files
authored
Create Find Words Containing Character.py
1 parent 4016e19 commit 5d2e028

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎Find Words Containing Character.py‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /