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.

Note: Length of the array will not exceed 10,000.

这个是一个经典的DP问题,  A[i] = A[i-1] + 1 if a[i] > a[i-1] else 1     (i > 0)   , init: A[0] = 1

[LeetCode] 329. Longest Increasing Path in a Matrix_Hard tag: Dynamic Programming, DFS, Memoization的一个前身.

code

T; O(n)    S; O(1)

class Solution:
def longestContinuesSubarry(self, nums):
if not nums: return 0
n = len(nums)
dp, ans = [1]*2, 1
for i in range(1, n):
if nums[i] > nums[i-1]:
dp[i%2] = dp[(i - 1) % 2] + 1
else:
dp[i%2] = 1
ans = max(ans, dp[i%2])
return ans

[LeetCode] 674. Longest Continuous Increasing Subsequence_Easy Dynamic Programming的更多相关文章

  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

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

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

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

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

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

  6. 【Leetcode_easy】674. Longest Continuous Increasing Subsequence

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

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

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

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

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

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

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

随机推荐

  1. Esper学习之八:EPL语法(四)

    关于EPL,已经写了三篇了,预估计了一下,除了今天这篇,后面还有5篇左右.大家可别嫌多,官方的文档对EPL的讲解有将近140页,我已经尽量将废话都干掉了,再配合我附上的例子,看我的10篇文章比那140 ...

  2. sencha touch list(列表) item(单行)单击事件触发顺序

    测试代码如下 Ext.define('app.view.new.List', { alternateClassName: 'newList', extend: 'app.view.util.MyLis ...

  3. [Sdoi2016]齿轮

    4602: [Sdoi2016]齿轮 Time Limit: 10 Sec  Memory Limit: 512 MB Submit: 613  Solved: 324 [Submit][Status ...

  4. Visual Studio 2013安装Update 3启动crash的解决方法

    Visual Studio 2013安装完Update 3后启动立刻crash,异常信息为: System.InvalidOperationException was unhandled Messag ...

  5. 23种设计模式之外观模式(Facade)

    外观模式是对象的结构模式,要求外部与一个子系统的通信必须通过一个统一的外观对象进行,为子系统中的一组接口提供一个一致的界面,外观模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 优点: 1 ...

  6. 【CF827F】Dirty Arkady's Kitchen DP

    [CF827F]Dirty Arkady's Kitchen 题意:给你一张n个点,m条边的有向图,每条边长度为1,第i条边在[li,ri)的时间内可以进入,求1到n的最短路. $n,m\le 5\t ...

  7. hiredis安装及测试

      (1) redis环境搭建    (2) hiredis下载地址及C API  github   (3) hiredis安装 我是把libhiredis.so放到/usr/local/lib/中, ...

  8. 170815、redis3.0安装配置

    下载地址http://redis.io/download 安装步骤: 1 首先需要安装gcc,把下载好的redis-3.0.0-rc2.tar.gz 放到linux /usr/local文件夹下 2 ...

  9. Yii2 使用json 和设置component 中'format' => yii\web\Response::FORMAT_JSON 的区别

    在Yii2中如果设置了 'response' => [  'format' => yii\web\Response::FORMAT_JSON,  'charset' => 'UTF- ...

  10. myeclipse bug

    在.metadata上方就不在workspace里面,复制黏贴在下方才可以发布运行