We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6fd5ea7 commit 95965efCopy full SHA for 95965ef
140-word-break-ii.js
@@ -1,3 +1,32 @@
1
+/**
2
+ * @param {string} s
3
+ * @param {string[]} wordDict
4
+ * @return {string[]}
5
+ */
6
+const wordBreak = function(s, wordDict) {
7
+ const set = new Set(wordDict)
8
+ return helper(s, 0, set)
9
+};
10
+
11
+function helper(str, idx, set) {
12
+ if(idx === str.length) return []
13
+ const res = []
14
+ for(let i = idx; i < str.length; i++) {
15
+ const tmp = str.slice(idx, i + 1)
16
+ if(set.has(tmp)) {
17
+ const arr = helper(str, i + 1, set)
18
+ if(i === str.length - 1) res.push(tmp)
19
+ for(let item of arr) {
20
+ res.push(`${tmp} ${item}`)
21
+ }
22
23
24
+ return res
25
+}
26
27
+// another
28
29
30
/**
31
* @param {string} s
32
* @param {string[]} wordDict
0 commit comments