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. Google APK下载

    在线下载google play中apk的网站 1.http://apps.evozi.com/apk-downloader 2.http://downloader-apk.com/ 3.http:// ...

  2. javascript取querystring,存储为hash

    function getUrlVars() { var vars = [], hash; var hashes = window.location.href.slice(window.location ...

  3. filter对数组和对象的过滤

    1,对数组的过滤 let arr = ['1', '2', '3'] let b = arr.filter(val => val === '2') console.log(b) // ['2] ...

  4. OpenStack cloud 第一天

    这是刚接触openstack时候,看到的第一篇文章,感触很深,自己很喜欢的一个词Horizon就是出自本文   ============================================ ...

  5. 深入浅出WPF之Binding的使用(一)

    在WPF中Binding可以比作数据的桥梁,桥梁的两端分别是Binding的源(Source)和目标(Target).一般情况下,Binding源是逻辑层对象,Binding目标是UI层的控件对象:这 ...

  6. 兵器簿之Alcatraz(插件管理神器)的配置和使用

    Alcatraz是一款开源框架,帮助我们管理和安装Xcode需要的一些插件,很赞,安装也很简单: 终端输入: curl -fsSL https://raw.githubusercontent.com/ ...

  7. ajax无刷新获取天气信息

    浏览器由于安全方面的问题,禁止ajax跨域请求其他网站的数据,但是可以再本地的服务器上获取其他服务器的信息,在通过ajax请求本地服务来实现: <?php header("conten ...

  8. hdu6390GuGuFishtion【数论】

    GuGuFishtion Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Tot ...

  9. .NET中的类型对象

    .NET中的任何类型,都有对应的一个类型对象.类型对象和类型实例(类型创建的一个对象)不是同一个概念. 类型对象包含类型的静态字段和方法,当类访问静态方法静态字段,实例调用方法时就会去类型对象中查找静 ...

  10. 《机器学习实战》中的程序清单2-1 k近邻算法(kNN)classify0都做了什么

    from numpy import * import operator import matplotlib import matplotlib.pyplot as plt from imp impor ...