diff --git a/problems/0674.最长连续递增序列.md b/problems/0674.最长连续递增序列.md index 31ab6b0e..614bff72 100644 --- a/problems/0674.最长连续递增序列.md +++ b/problems/0674.最长连续递增序列.md @@ -218,6 +218,49 @@ class Solution: Go: +Javascript: + +> 动态规划: +```javascript +const findLengthOfLCIS = (nums) => { + let dp = Array(nums.length).fill(1); + + + for(let i = 0; i < nums.length - 1; i++) { + if(nums[i+1] > nums[i]) { + dp[i+1] = dp[i]+ 1; + } + } + + return Math.max(...dp); +}; +``` + +> 贪心法: +```javascript +const findLengthOfLCIS = (nums) => { + if(nums.length === 1) { + return 1; + } + + let maxLen = 1; + let curMax = 1; + let cur = nums[0]; + + for(let num of nums) { + if(num > cur) { + curMax += 1; + maxLen = Math.max(maxLen, curMax); + } else { + curMax = 1; + } + cur = num; + } + + return maxLen; +}; +``` +