File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,49 @@ class Solution:
218
218
219
219
Go:
220
220
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
+
221
264
222
265
223
266
You can’t perform that action at this time.
0 commit comments