We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8bb6bc0 commit a952becCopy full SHA for a952bec
src/my_project/interviews/top_amazon_questions_round_1/word_break_ii.py
@@ -0,0 +1,22 @@
1
+from typing import List, Union
2
+
3
+class Solution:
4
+ def wordBreak(self, s: str, wordDict: List[str]) -> List[str]:
5
+ res = []
6
+ wordSet = set(wordDict)
7
8
+ def helper(i, cur, path):
9
+ if i == len(s):
10
+ if not cur:
11
+ res.append(' '.join(path))
12
+ return
13
14
+ cur += s[i] # include current character
15
16
+ if cur in wordSet:
17
+ helper(i + 1, '', path + [cur]) # cut here
18
19
+ helper(i + 1, cur, path) # continue building cur
20
21
+ helper(0, '', [])
22
+ return res
0 commit comments