@@ -229,6 +229,8 @@ var uniquePathsWithObstacles = function (obstacleGrid) {
229229
230230## 2、序列类型(40%)
231231
232+ ### Sequence
233+
232234##### [ 70. 爬楼梯] ( https://leetcode-cn.com/problems/climbing-stairs/ )
233235
234236``` js
@@ -295,7 +297,15 @@ function jump(nums: number[]): number { //从前往后推
295297
296298##### [ 132. 分割回文串 II] ( https://leetcode-cn.com/problems/palindrome-partitioning-ii/ )
297299
298- 给你一个字符串 ` s ` ,请你将 ` s ` 分割成一些子串,使每个子串都是回文。返回符合要求的 ** 最少分割次数** 。
300+ 给你一个字符串 ` s ` ,请你将 ` s ` 分割成一些子串,使每个子串都是回文。返回符合要求的 最少分割次数 。
301+
302+ ``` tsx
303+
304+ ```
305+
306+ ##### [ 300. 最长递增子序列] ( https://leetcode-cn.com/problems/longest-increasing-subsequence/ )
307+
308+ 给你一个整数数组 ` nums ` ,找到其中最长严格递增子序列的长度。
299309
300310``` tsx
301311function lengthOfLIS(nums : number []): number {
@@ -311,3 +321,51 @@ function lengthOfLIS(nums: number[]): number {
311321};
312322```
313323
324+ ##### [ 139. 单词拆分] ( https://leetcode-cn.com/problems/word-break/ )
325+
326+ 给定一个** 非空** 字符串 * s* 和一个包含** 非空** 单词的列表 * wordDict* ,判定 * s* 是否可以被空格拆分为一个或多个在字典中出现的单词。
327+
328+ ``` tsx
329+ function wordBreak(s : string , wordDict : string []): boolean {
330+ const len: number = s .length
331+ const dp: boolean [] = new Array (len + 1 ).fill (false )
332+ const wordDictSet: Set <string > = new Set (wordDict )
333+ dp [0 ] = true
334+ for (let i = 1 ; i <= len ; i ++ ) {
335+ for (let j = 0 ; j < i ; j ++ ) {
336+ if (dp [j ] && wordDictSet .has (s .slice (j , i ))) {
337+ dp [i ] = true
338+ break
339+ }
340+ }
341+ }
342+ return dp [len ]
343+ };
344+ ```
345+
346+ ### Two Sequences DP
347+
348+ ##### [ 1143. 最长公共子序列] ( https://leetcode-cn.com/problems/longest-common-subsequence/ )
349+
350+ 给定两个字符串 ` text1 ` 和 ` text2 ` ,返回这两个字符串的最长 ** 公共子序列** 的长度。如果不存在 ** 公共子序列** ,返回 ` 0 ` 。
351+
352+ ``` tsx
353+ function longestCommonSubsequence(text1 : string , text2 : string ): number {
354+ const col: number = text1 .length
355+ const row: number = text2 .length
356+ const dp: number [][] = new Array (row + 1 ).fill (0 ).map (() => new Array (col + 1 ).fill (0 ))
357+ for (let i = 1 ; i <= row ; i ++ ) {
358+ for (let j = 1 ; j <= col ; j ++ ) {
359+ if (text2 [i - 1 ] === text1 [j - 1 ]) {
360+ dp [i ][j ] = dp [i - 1 ][j - 1 ] + 1
361+ } else {
362+ dp [i ][j ] = Math .max (dp [i - 1 ][j ], dp [i ][j - 1 ])
363+ }
364+ }
365+ }
366+ return dp [row ][col ]
367+ };
368+ ```
369+
370+
371+
0 commit comments