Skip to content

Commit 34bae79

Browse files
Create 0030H. Substring with Concatenation of All Words.py
1 parent a928cce commit 34bae79

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#Runtime: 1752 ms, faster than 17.44% of Python3 online submissions for Substring with Concatenation of All Words.
2+
#Memory Usage: 14.4 MB, less than 93.14% of Python3 online submissions for Substring with Concatenation of All Words.
3+
4+
class Solution:
5+
def findSubstring(self, s: str, words: List[str]) -> List[int]:
6+
w_l = len(words[0])
7+
w_n = len(words)
8+
re_ind = []
9+
index_adj = 0
10+
while len(s) >= w_n*w_l:
11+
w_index = []
12+
for i in words:
13+
try:
14+
w_index.append(s.index(i))
15+
except:
16+
return re_ind
17+
w_index.sort()
18+
s = s[w_index[0]:]
19+
index_adj += w_index[0]
20+
temp_words = [] + words
21+
for i in range(w_n):
22+
if s[w_l*i:w_l+w_l*i] in temp_words:
23+
temp_words.remove(s[w_l*i:w_l+w_l*i])
24+
else:
25+
break
26+
if not temp_words:
27+
re_ind.append(index_adj)
28+
s = s[1:]
29+
index_adj += 1
30+
return re_ind

0 commit comments

Comments
 (0)