[Leetcode]674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuous increasing subsequence.
Example 1:
Input: [1,3,5,4,7]
Output: 3
Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3.
Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4.
Example 2:
Input: [2,2,2,2,2]
Output: 1
Explanation: The longest continuous increasing subsequence is [2], its length is 1.
Note: Length of the array will not exceed 10,000.
思路:如果数组的长度小于2,则直接返回数组的长度;否则设置两个变量maxLength=1和length=1,length用于统计
连续递增的子序列长度,一旦递增中断,则lenth重置为1,继续后面的统计。这个过程中,最大的length值赋给maxLength
class Solution {
public int findLengthOfLCIS(int[] nums) {
if (nums.length<2)
return nums.length;
int maxLength = 1,length = 1;
for (int i=1;i<nums.length;i++){
if (nums[i]>nums[i-1])
length++;
else
length = 1;
if (length>maxLength)
maxLength = length;
}
return maxLength;
}
}
[Leetcode]674. Longest Continuous Increasing Subsequence的更多相关文章
- [LeetCode] 674. Longest Continuous Increasing Subsequence 最长连续递增序列
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)
Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...
- LeetCode 674. Longest Continuous Increasing Subsequence最长连续递增序列 (C++/Java)
题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...
- leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence
Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...
- 【Leetcode_easy】674. Longest Continuous Increasing Subsequence
problem 674. Longest Continuous Increasing Subsequence solution class Solution { public: int findLen ...
- 【LeetCode】674. Longest Continuous Increasing Subsequence 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 空间压缩DP 日期 题目地址:https: ...
- [LeetCode&Python] Problem 674. Longest Continuous Increasing Subsequence
Given an unsorted array of integers, find the length of longest continuousincreasing subsequence (su ...
- [LeetCode] 674. Longest Continuous Increasing Subsequence_Easy Dynamic Programming
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...
- 674. Longest Continuous Increasing Subsequence最长连续递增子数组
[抄题]: Given an unsorted array of integers, find the length of longest continuous increasing subseque ...
随机推荐
- tp5.0.7 修复getshell漏洞
这里 接手项目用的是 tp5.0.7 突然想到前段事件的tp bug 事件 就试了下 发现确实有这种情况 参考帖子: https://bbs.ichunqiu.com/thread-48687-1-1 ...
- 第三方npm包安装失败
最近升级一些第三方库,老是出现无法正常安装npm的现象. 一.问题现象 1.webpack4安装失败 // 报错信息 webpack Maximum call stack size exceeded ...
- Flask消息验证与提示
一,消息提示基本语法. 1,先新建一个Flask工作空间. 2,新建后自动得到一个app.py文件,直接运行可以看到基本效果.然后引入 from flask import flash.使用这个flas ...
- 刚学的vue.js的单一事件管理组件通信
第一次在博客园写的技术分享,写的不好的话各位大神多体谅,好啦进入主题 说说思路 首先 第一步,准备一个空的示例对象 var Event=new Vue(); 第二步,准备发送的数据 Event.$em ...
- java用jsoup解析HTML
步骤 1获取document对象 //方法一 Document doc = Jsoup.connect(网址).get() //方法二 Document doc = Jsoup.parse(html字 ...
- js 原生转json 可以v8中运行
// load("D:/jsontest.js"); function test1(vvv) { print(vvv); } //把json str 转 json obj func ...
- vue-cli+mock.js+axios模拟前后台数据交互
最近工作不是很忙,自己做了一个vue的移动端的小项目,涉及到后台数据的时候,网上查阅了一些资料,因为是自己写的项目没有后台只能自己模拟数据,刚开始就自己写了一些静态数据后来觉得尽量模拟真实的比较好些, ...
- NOIP-珠心算
题目描述 珠心算是一种通过在脑中模拟算盘变化来完成快速运算的一种计算技术.珠心算训练,既能够开发智力,又能够为日常生活带来很多便利,因而在很多学校得到普及. 某学校的珠心算老师采用一种快速考察珠心算加 ...
- JavaScript递归
什么是递归? 在函数的内部调用自己 下面有一个例子,通过这个例子,大家就可以了解什么是递归 function fun(){ console.log(new Date()) //获取当前时间,并在控制台 ...
- [GIT] 更新.repo目录
cd .repo/manifests/ git co -f git pull