-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringMatching.py
More file actions
52 lines (42 loc) · 1.41 KB
/
stringMatching.py
File metadata and controls
52 lines (42 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 1408. 数组中的字符串匹配
from typing import List
class Solution:
# def stringMatching(self, words: List[str]) -> List[str]:
# res = []
# for i, word in enumerate(words):
# for w in words[:i] + words[i+1:]:
# if word in w:
# res.append(word)
# break
# return res
# def stringMatching(self, words: List[str]) -> List[str]:
# res = []
# for i, x in enumerate(words):
# for j, y in enumerate(words):
# if i != j and x in y:
# res.append(x)
# break
# return res
# def stringMatching(self, words: List[str]) -> List[str]:
# res = []
# for i, x in enumerate(words):
# for j, y in enumerate(words):
# if i != j and x in y:
# res.append(x)
# break
# return res
def stringMatching(self, words: List[str]) -> List[str]:
res = []
for i, x in enumerate(words):
for j, y in enumerate(words):
if i != j and x in y:
res.append(x)
break
return res
s = Solution()
words = ["mass","as","hero","superhero"]
print(s.stringMatching(words))
words = ["leetcode","et","code"]
print(s.stringMatching(words))
words = ["blue","green","bu"]
print(s.stringMatching(words))