说是数组,但是感觉贪心更合适,和跳跃数组也有点像。维护递增长度和最大递增长度即可求出结果!!!
class Solution(object):
def findLengthOfLCIS(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if not nums:
return 0
answer = 0
increaseLength = 1
for i in range(1, len(nums)):
if nums[i] > nums[i-1]:
increaseLength += 1
else:
answer = max(increaseLength, answer)
increaseLength = 1
answer = max(increaseLength, answer)
return answer
网友评论