zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    mysql general log使用介绍
    是否可以根据GTID 选出日志最新的实例
    python踩坑现场,看起来一样的两个字符串,却不相等
    sql case when的使用
    golang 匿名结构体成员,具名结构体成员,继承,组合
    golang go-sql-driver/mysql基本原理
    raft协议中的日志安全性
    go get 安装 go.etcd.io etcd clientv3 报错
    ZGC
    发现jdk9之后,AQS代码有啥变化了吗
  • 原文地址:https://www.cnblogs.com/immiao0319/p/8902000.html
Copyright © 2011-2022 走看看