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

[抄题]:

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

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. 

 [暴力解法]:

时间分析:

空间分析:

 [优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

本题最低下限是1,因为起码有一个数也算是连续

[思维问题]:

[一句话思路]:

数组连续性的问题,用本地、全局变量+三元表达式即可

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

  [五分钟肉眼debug的结果]:

[总结]:

本题最低下限是1,因为起码有一个数也算是连续

[复杂度]:Time complexity: O(n) Space complexity: O(1)

[英文数据结构或算法,为什么不用别的数据结构或算法]:

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

673. Number of Longest Increasing Subsequence 一共有几个?最值、可行、个数,用dp了

 [代码风格] :

class Solution {
    public int findLengthOfLCIS(int[] nums) {
        if (nums == null || nums.length == 0) {
            return 0;
        }
        
        int max = 1, maxHere = 1;
        for (int i = 1; i < nums.length; i++) {
            max = Math.max(max, maxHere = (nums[i] > nums[i - 1]) ? maxHere + 1 : 1);
        }
        
        return max;
    }
}
View Code
原文地址:https://www.cnblogs.com/immiao0319/p/8902000.html