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. 《About Face 3:交互设计精髓》读书笔记(一)

    第一章 目标导向设计 当今数字产品的创造过程 市场营销人员对于产品设计过程的贡献,通常局限于需求列表这些需求同用户的实际需要与期望无关,主要在于追赶竞争对手,按照任务清单管理IT资源,以及基于市场调查 ...

  2. WPF中的ObservableCollection数据绑定

    使用时ObservableCollection必须使用get set属性声明,才能成功的绑定到控件.

  3. [转]HTML5 script 标签的 crossorigin 属性到底有什么用?

    HTML5 script 标签的 crossorigin 属性到底有什么用? 最近Bootstrap 4已经正式发布了,可能已经有爱尝鲜的小伙伴在 alpha 阶段就尝试过 BS4.不过今天要说的不是 ...

  4. [POJ3630]Phone List (Tire)

    题意 trie字典树模板 LOJ有中文翻译https://loj.ac/problem/10049 思路 TIRE 代码 之前在LOJ上做过 直接交了 #include<cstdio> # ...

  5. json字符串的拼接

    关于json字符串的解析与拼接,第一次接触,留下个笔记了.......解析,是改的代码,拼接是纯的,解析就不说了,笔记一下拼接了 关于解析主要分三部分,一个是第一层处理,一个是第二层处理,一个是进行& ...

  6. Linux 下redis 集群搭建练习

    Redis集群 学习参考:https://blog.csdn.net/jeffleo/article/details/54848428https://my.oschina.net/iyinghui/b ...

  7. h5直接分享的实现方案

    首先得知道,h5是无法直接通过js跳转到微信或QQ等软件进行分享, 参照新浪的分享方式,在uc浏览器和QQ浏览器等主流浏览器中是可以直接分享的, 原因是uc浏览器和QQ浏览器这样的主流浏览器是自带分享 ...

  8. 小程序wx:for循环列表数量的限制

    数据有100条,我们只要页面显示一部分,就要通过index来限制.index<3,就是显示序列0,1,2这三条数据.具体写法: <block wx:for='{{list}}' wx:ke ...

  9. 第一个servlet程序

    在Eclipse中新建一个Dynamic Web Project 在WebContent下面添加index.jsp <%@ page language="java" cont ...

  10. GameFreamWork框架----事件系统的应用

    事件系统用途广泛,对处理玩家数据有很大帮助(玩家金币,经验,等级),让数据多次调用,降低耦合 在unity中应用(以玩家金币发生变化来演示); 1).注册监听 2).移出监听 3).金币发生变化的时候 ...