当前位置:网站首页>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
};
```
边栏推荐
- [EI search] important information conference of the 6th International Conference on materials engineering and advanced manufacturing technology (meamt 2022) in 2022 website: www.meamt Org meeting time
- 【TA-霜狼_may-《百人计划》】2.4 传统经验光照模型
- 206.反转链表
- 有效的 @SuppressWarnings 警告名称
- 10. 正则表达式匹配
- 互联网行业最佳产品开发流程 推荐!
- jeecgboot输出日志,@Slf4j的使用方法
- Analyse et cas du modèle pageobject
- SEM of C language_ Tvariable type
- [TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
猜你喜欢
Future of NTF and trends in 2022
MFC window scroll bar usage
The programmer's girlfriend gave me a fatigue driving test
[TA frost wolf \u may- hundred people plan] 1.2.1 vector basis
431. 将 N 叉树编码为二叉树 DFS
[TA frost wolf \u may- hundred people plan] 2.4 traditional empirical lighting model
Jenkins自动清理构建历史
The method to measure the similarity of two vectors: cosine similarity, pytorch calculate cosine similarity: torch nn. CosineSimilarity(dim=1, eps=1e-08)
Addition without addition, subtraction, multiplication and division
Go learning --- unit test subtest
随机推荐
Appium fundamentals of automated testing - basic principles of appium
409. longest palindrome
Its appearance makes competitors tremble. Interpretation of Sony vision-s 02 products
Libevent Library Learning
Leetcode:829. Sum of continuous integers
jeecgboot输出日志,@Slf4j的使用方法
Idea plug-in backup table
Cygwin的下载和安装配置
166. 分数到小数
392. 判断子序列
JMeter学习笔记2-图形界面简单介绍
Huawei simulator ENSP - hcip - Hybrid Experiment 2
线程常用方法与守护线程
【TA-霜狼_may-《百人计划》】2.2 模型与材质空间
Appium自动化测试基础--补充:C/S架构和B/S架构说明
6. zigzag transformation
Database DDL (data definition language) knowledge points
Access denied for user ‘ODBC‘@‘localhost‘ (using password: NO)
242. 有效的字母异位词
【TA-霜狼_may-《百人計劃》】1.2.1 向量基礎