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 c6260ae commit 1f58190Copy full SHA for 1f58190
word-break/yihyun-kim1.js
@@ -0,0 +1,20 @@
1
+/**
2
+ * @param {string} s
3
+ * @param {string[]} wordDict
4
+ * @return {boolean}
5
+ */
6
+const wordBreak = (s, wordDict) => {
7
+ const dp = new Array(s.length + 1).fill(false);
8
+ dp[0] = true;
9
+
10
+ for (let i = 1; i <= s.length; i++) {
11
+ for (const word of wordDict) {
12
+ const start = i - word.length;
13
+ if (start >= 0 && dp[start] && s.slice(start, i) === word) {
14
+ dp[i] = true;
15
+ }
16
17
18
19
+ return dp[s.length];
20
+};
0 commit comments