Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8907c71

Browse files
Merge pull requestyoungyangyang04#493 from jackeyjia/patch-13
add js solution for findLengthOfLCIS
2 parents64673f2 +2a24739 commit8907c71

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+
constfindLengthOfLCIS= (nums)=> {
242+
if(nums.length===1) {
243+
return1;
244+
}
245+
246+
let maxLen=1;
247+
let curMax=1;
248+
let cur= nums[0];
249+
250+
for(let numof 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)

[8]ページ先頭

©2009-2025 Movatter.jp