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的更多相关文章

  1. [LeetCode] 674. Longest Continuous Increasing Subsequence 最长连续递增序列

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  2. LeetCode 674. Longest Continuous Increasing Subsequence (最长连续递增序列)

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  3. LeetCode 674. Longest Continuous Increasing Subsequence最长连续递增序列 (C++/Java)

    题目: Given an unsorted array of integers, find the length of longest continuous increasing subsequenc ...

  4. leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence

    Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...

  5. 【Leetcode_easy】674. Longest Continuous Increasing Subsequence

    problem 674. Longest Continuous Increasing Subsequence solution class Solution { public: int findLen ...

  6. 【LeetCode】674. Longest Continuous Increasing Subsequence 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 动态规划 空间压缩DP 日期 题目地址:https: ...

  7. [LeetCode&Python] Problem 674. Longest Continuous Increasing Subsequence

    Given an unsorted array of integers, find the length of longest continuousincreasing subsequence (su ...

  8. [LeetCode] 674. Longest Continuous Increasing Subsequence_Easy Dynamic Programming

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence (s ...

  9. 674. Longest Continuous Increasing Subsequence最长连续递增子数组

    [抄题]: Given an unsorted array of integers, find the length of longest continuous increasing subseque ...

随机推荐

  1. 网络攻击技术:SQL Injection(sql注入)

    网络攻击技术开篇——SQL Injection   1.1.1 摘要 日前,国内最大的程序员社区CSDN网站的用户数据库被黑客公开发布,600万用户的登录名及密码被公开泄露,随后又有多家网站的用户密码 ...

  2. python-关于字典与列表的一个作业

    题目是这样的: 给定一个字典dict1,将其转换成dict2: dict1 = { 'fetal':[{u'key': u'sjzx_sy22_121.201.56.5', u'doc_count': ...

  3. 微软官网tools

    DHCP/AD域插件: 远程管理工具(含DHCP/AD域) 安装网址: https://www.microsoft.com/zh-cn/download/details.aspx?id=7887 程序 ...

  4. xpath路径定位

    preceding-sibling选择同级层所有节点向前查找 //div[@id='id1']/preceding-sibling::div/a 例如:“更多产”超链接的同级向上数第二个元素,即“登陆 ...

  5. POJ3436 Command Network [最小树形图]

    POJ3436 Command Network 最小树形图裸题 傻逼poj回我青春 wa wa wa 的原因竟然是需要%.2f而不是.2lf 我还有英语作业音乐作业写不完了啊啊啊啊啊啊啊啊啊 #inc ...

  6. Go资源

    go语言实现的设计模式 http://tmrts.com/go-patterns/ https://design-patterns.readthedocs.io/zh_CN/latest/index. ...

  7. Windows下如何将一个文件夹通过Git上传到GitHub上(转)

    在通过windows系统的电脑上写代码,需要将项目上传到GitHub上去.比如在Pycharm上写Django后端,整个项目是一个文件夹的形式,那么怎么才能这个文件夹通过Git命令上传到GitHub上 ...

  8. 使用ftp读取文件夹中的多个文件,并删除

    public class FTPUtils { private static final Logger LOG = LoggerFactory.getLogger(FTPUtils.class); / ...

  9. 页面的input唤醒软键盘再收起后,页面会出现软键盘高度的空白背景

    微信浏览器在版本6.7.4及以上会有这个bug:页面的input唤醒软键盘再收起后,页面会出现软键盘高度的空白背景,触摸到滚动条会消失恢复! 解决代码 后台框架嵌入iframe的情景,iframe内部 ...

  10. 分享几个有意思的css js工具网站

    一.VOCABS(css html术语) vocabs 适合初学者快速认知各个代码的术语. 二.OverAPI(语言参考手册,几乎包含所有语言) OverAPI 适合快速查阅相关语言api 三.Jav ...