# 674. Longest Continuous Increasing Subsequence 最长连续递增序列

@TOC

## # 题目描述

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.
``````

## # 解题方法

### # 动态规划

``````class Solution(object):
def findLengthOfLCIS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if not nums: return 0
N = len(nums)
dp = [1] * N
for i in range(1, N):
if nums[i] > nums[i - 1]:
dp[i] = dp[i - 1] + 1
return max(dp)
``````

### # 空间压缩DP

``````class Solution(object):
def findLengthOfLCIS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
longest = 0
cur = 0
for i in range(len(nums)):
if i == 0 or nums[i] > nums[i - 1]:
cur += 1
longest = max(longest, cur)
else:
cur = 1
return longest
``````

``````class Solution(object):
def findLengthOfLCIS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if not nums: return 0
N = len(nums)
dp = 1
res = 1
for i in range(1, N):
if nums[i] > nums[i - 1]:
dp += 1
res = max(res, dp)
else:
dp = 1
return res
``````

## # 日期

2018 年 1 月 29 日 2018 年 11 月 19 日 —— 周一又开始了