Skip to content

Commit

Permalink
Merge pull request youngyangyang04#1349 from xiaofei-2020/dp41
Browse files Browse the repository at this point in the history
添加(0300.最长上升子序列.md):增加typescript版本
  • Loading branch information
youngyangyang04 authored Jun 10, 2022
2 parents 1ef962f + 54d10fc commit d00168d
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions problems/0300.最长上升子序列.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,27 @@ const lengthOfLIS = (nums) => {
};
```

TypeScript

```typescript
function lengthOfLIS(nums: number[]): number {
/**
dp[i]: 前i个元素中,以nums[i]结尾,最长子序列的长度
*/
const dp: number[] = new Array(nums.length).fill(1);
let resMax: number = 0;
for (let i = 0, length = nums.length; i < length; i++) {
for (let j = 0; j < i; j++) {
if (nums[i] > nums[j]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
resMax = Math.max(resMax, dp[i]);
}
return resMax;
};
```




Expand Down

0 comments on commit d00168d

Please sign in to comment.