当前位置:网站首页>674. longest continuous increasing sequence force buckle JS
674. longest continuous increasing sequence force buckle JS
2022-07-01 03:52:00 【Big drumsticks are best】
Given an unordered array of integers , Find the longest and Successive increasing subsequences , And return the length of the sequence .
Successive increasing subsequences It can be made up of two subscripts l and r(l < r) determine , If for each l <= i < r, There are nums[i] < nums[i + 1] , So the subsequence [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] It's a continuous increasing subsequence .
Example 1:
Input :nums = [1,3,5,4,7]
Output :3
explain : The longest continuous increasing sequence is [1,3,5], The length is 3.
Even though [1,3,5,7] It's also a subsequence of ascending order , But it's not continuous , because 5 and 7 In the original array is 4 separate .
Example 2:
Input :nums = [2,2,2,2,2]
Output :1
explain : The longest continuous increasing sequence is [2], The length is 1.
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
### Their thinking
Here is the solution
Greedy Algorithm
a by b Maximum value of previous value
b Every time I meet the next one smaller than this, I will start a new wave
### Code
```javascript
/**
* @param {number[]} nums
* @return {number}
*/
var findLengthOfLCIS = function(nums) {
let a=1,b=1
let len=nums.length
for(let i=0;i<len-1;i++){
if(nums[i]<nums[i+1]){
b+=1
a=Math.max(a,b)
}
else{
b=1
}
}
return a
};
```
边栏推荐
- Appium automation test foundation -- supplement: c/s architecture and b/s architecture description
- [ta - Frost Wolf May - 100 people plan] 1.2.1 base vectorielle
- 【伸手党福利】开发人员重装系统顺序
- Libevent Library Learning
- 25.K个一组翻转链表
- The combination of applet container technology and IOT
- jeecgboot输出日志,@Slf4j的使用方法
- 187. repeated DNA sequences
- 盘点华为云GaussDB(for Redis)六大秒级能力
- 【TA-霜狼_may-《百人计划》】1.2.2 矩阵计算
猜你喜欢

互联网行业最佳产品开发流程 推荐!

【TA-霜狼_may-《百人計劃》】2.3 常用函數介紹

Why can't you find the corresponding function by clicking go to definiton (super easy has a diagram)

Libevent Library Learning

【TA-霜狼_may-《百人计划》】2.3 常用函数介绍

Volley parsing data shows networking failure

【TA-霜狼_may-《百人計劃》】1.2.1 向量基礎

TEC: Knowledge Graph Embedding with Triple Context

【TA-霜狼_may-《百人计划》】1.2.3 MVP矩阵运算

The programmer's girlfriend gave me a fatigue driving test
随机推荐
【EI会议】2022年国际土木与海洋工程联合会议(JCCME 2022)
10. 正则表达式匹配
[TA frost wolf \u may- hundred people plan] 2.3 introduction to common functions
30. 串联所有单词的子串
318. 最大单词长度乘积
使用selenium自动化测试工具爬取高考相关院校专业招生分数线及排名情况
205. isomorphic string
8. 字符串转换整数 (atoi)
431. encode n-ary tree as binary tree DFS
[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
72. edit distance
409. 最长回文串
Random seed torch in deep learning manual_ seed(number)、torch. cuda. manual_ seed(number)
[ta- frost wolf \u may- hundred people plan] 1.1 rendering pipeline
The combination of applet container technology and IOT
Appium fundamentals of automated testing - basic principles of appium
[EI conference] the Third International Conference on nanomaterials and nanotechnology in 2022 (nanomt 2022)
Deep learning | rnn/lstm of naturallanguageprocessing
在 C 中声明函数之前调用函数会发生什么?
jeecgboot输出日志,@Slf4j的使用方法