当前位置:网站首页>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检索】2022年第六届材料工程与先进制造技术国际会议(MEAMT 2022)重要信息会议网址:www.meamt.org会议时间:2022年9月23-25日召开地点:中国南京截稿时间:2
- 快速筛选打卡时间日期等数据:EXCEL筛选查找某一时间点是否在某一时间段内
- idea插件备份表
- [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
- Why can't you find the corresponding function by clicking go to definiton (super easy has a diagram)
- 208. 实现 Trie (前缀树)
- 166. 分数到小数
- Blueprism registration, download and install -rpa Chapter 1
- Review column - message queue
- Deep learning | rnn/lstm of naturallanguageprocessing
猜你喜欢

Future of NTF and trends in 2022

[TA frost wolf \u may - "hundred people plan"] 2.1 color space

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

How keil displays Chinese annotations (simple with pictures)

Valentine's Day is nothing.

Network metering - application layer

AfxMessageBox和MessageBox的用法

Appium自动化测试基础 — APPium基本原理

Error: plug ins declaring extensions or extension points must set the singleton directive to true

【TA-霜狼_may-《百人计划》】1.4 PC手机图形API介绍
随机推荐
392. judgment subsequence
171. Excel 表列序号
You cannot right-click F12 to view the source code solution on the web page
All in one 1086: Jiaogu conjecture
[ta- frost wolf \u may- hundred people plan] 2.2 model and material space
[TA frost wolf \u may - "hundred people plan"] 2.1 color space
Develop industrial Internet with the technical advantages of small programs
5. [WebGIS practice] software operation - service release and permission management
PageObject模式解析及案例
程序员女友给我做了一个疲劳驾驶检测
C语言的sem_t变量类型
165. compare version numbers
Edge浏览器的小技巧:Enter+Ctrl可以自动将地址栏转换为网址
389. 找不同
Leetcode 31 next spread, leetcode 64 minimum path sum, leetcode 62 different paths, leetcode 78 subset, leetcode 33 search rotation sort array (modify dichotomy)
How keil displays Chinese annotations (simple with pictures)
Leetcode: offer 59 - I. maximum value of sliding window
Online public network security case nanny level tutorial [reaching out for Party welfare]
【TA-霜狼_may-《百人計劃》】1.2.1 向量基礎
165. 比较版本号