Skip to content

Commit 8907c71

Browse files
Merge pull request youngyangyang04#493 from jackeyjia/patch-13
add js solution for findLengthOfLCIS
2 parents 64673f2 + 2a24739 commit 8907c71

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

problems/0674.最长连续递增序列.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,49 @@ class Solution:
218218

219219
Go:
220220

221+
Javascript:
222+
223+
> 动态规划:
224+
```javascript
225+
const findLengthOfLCIS = (nums) => {
226+
let dp = Array(nums.length).fill(1);
227+
228+
229+
for(let i = 0; i < nums.length - 1; i++) {
230+
if(nums[i+1] > nums[i]) {
231+
dp[i+1] = dp[i]+ 1;
232+
}
233+
}
234+
235+
return Math.max(...dp);
236+
};
237+
```
238+
239+
> 贪心法:
240+
```javascript
241+
const findLengthOfLCIS = (nums) => {
242+
if(nums.length === 1) {
243+
return 1;
244+
}
245+
246+
let maxLen = 1;
247+
let curMax = 1;
248+
let cur = nums[0];
249+
250+
for(let num of nums) {
251+
if(num > cur) {
252+
curMax += 1;
253+
maxLen = Math.max(maxLen, curMax);
254+
} else {
255+
curMax = 1;
256+
}
257+
cur = num;
258+
}
259+
260+
return maxLen;
261+
};
262+
```
263+
221264

222265

223266

0 commit comments

Comments
 (0)