Skip to content

Commit c6c73f2

Browse files
committed
update: 139
1 parent 3918d8e commit c6c73f2

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
8787
| 135 | [Candy](https://leetcode.com/problems/candy/) | [JavaScript](./src/candy/res.js) | Hard |
8888
| 136 | [Single Number](https://leetcode.com/problems/single-number/) | [JavaScript](./src/single-number/res.js) | Easy |
8989
| 137 | [Single Number II](https://leetcode.com/problems/single-number-ii/) | [JavaScript](./src/single-number-ii/res.js) | Medium |
90+
| 139 | [word-break](https://leetcode.com/problems/word-break/) | [TypeScript](./src/word-break/res.ts) | Medium |
9091
| 151 | [Reverse Words in a String](https://leetcode.com/problems/reverse-words-in-a-string/) | [JavaScript](./src/reverse-words-in-a-string/res.js) | Medium |
9192
| 152 | [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/) | [JavaScript](./src/maximum-product-subarray/res.js) | Medium |
9293
| 153 | [Find Minimum in Rotated Sorted Array](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) | [JavaScript](./src/find-minimum-in-rotated-sorted-array/res.js) | Medium |

src/word-break/res.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function wordBreak(s: string, wordDict: string[]): boolean {
2+
if (!s) {
3+
return true;
4+
}
5+
const n = s.length;
6+
const dp = new Array(n+1).fill(false);
7+
dp[0] = true;
8+
9+
for (let i = 0; i < n; i++) {
10+
for (let j = i+1; j <= n+1; j++) {
11+
if (dp[i] && wordDict.includes(s.slice(i, j))) {
12+
dp[j] = true;
13+
}
14+
}
15+
}
16+
17+
return dp[n];
18+
};

0 commit comments

Comments
 (0)