博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
674. Longest Continuous Increasing Subsequence最长连续递增子数组
阅读量:4698 次
发布时间:2019-06-09

本文共 1361 字,大约阅读时间需要 4 分钟。

[抄题]:

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

Example 1:

Input: [1,3,5,4,7]Output: 3Explanation: 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: 1Explanation: 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

你可能感兴趣的文章
LeetCode - Same Tree
查看>>
Python dict get items pop update
查看>>
[置顶] 程序员必知(二):位图(bitmap)
查看>>
130242014036-(2)-体验敏捷开发
查看>>
constexpr
查看>>
Nginx 流量和连接数限制
查看>>
课堂作业1
查看>>
IE8/9 本地预览上传图片
查看>>
Summary of CRM 2011 plug-in
查看>>
Eclipse+Maven环境下java.lang.OutOfMemoryError: PermGen space及其解决方法
查看>>
安全漏洞之Java
查看>>
Oracle 组函数count()
查看>>
Session的使用过程中应注意的一个小问题
查看>>
SDK,API,DLL名词解释
查看>>
试探算法
查看>>
jquery.validation.js 使用
查看>>
数据库高级查询
查看>>
C语言实现封装、继承和多态
查看>>
创建文件
查看>>
Nginx 相关介绍
查看>>