题目:
给定一个未经排序的整数数组,找到最长且连续的的递增序列,并返回该序列的长度。
示例:
输入: [1,3,5,4,7]
输出: 3
解释: 最长连续递增序列是 [1,3,5], 长度为3。
尽管 [1,3,5,7] 也是升序的子序列, 但它不是连续的,因为5和7在原数组里被4隔开。
来源链接:https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence。
代码:
class Solution(object):
def findLengthOfLCIS(self, nums):
Max_length=1
if len(nums)!=0:
temp_value=nums[0]
temp_length=1
for i in range(1,len(nums)):
if nums[i] > temp_value:
temp_length+=1
temp_value=nums[i]
else:
if temp_length > Max_length:
Max_length=temp_length
temp_length=1
temp_value=nums[i]
if temp_length > Max_length:
Max_length=temp_length
return Max_length
else:
return 0