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 eaa4ece commit 742008bCopy full SHA for 742008b
word-break/soobing.ts
@@ -0,0 +1,15 @@
1
+function wordBreak(s: string, wordDict: string[]): boolean {
2
+ const dp = new Array(s.length + 1).fill(false);
3
+ dp[s.length] = true;
4
+
5
+ for (let i = s.length - 1; i >= 0; i--) {
6
+ for (const word of wordDict) {
7
+ if (i + word.length <= s.length && s.slice(i, i + word.length) === word) {
8
+ dp[i] = dp[i + word.length];
9
+ }
10
11
+ if (dp[i]) break;
12
13
14
+ return dp[0];
15
+}
0 commit comments