674. 最长连续递增序列

伪装成LIS的简单题目

class Solution(object):
    def findLengthOfLCIS(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        n = len(nums)
        
        # guard clause
        # 这个可比lis简单多了, 维护两个状态就ok
        if n == 1:
          return 1
        
        max_lcis = 0
        tmp_lcis = 1
        for i in range(1,n):
          # 关键步骤就在此
          if nums[i] > nums[i-1]:
            tmp_lcis +=1
          else:
            tmp_lcis = 1
            
          max_lcis = max(max_lcis,tmp_lcis)
        return max_lcis

    原文作者:cptn3m0
    原文地址: https://www.jianshu.com/p/ebbc1dd099b5
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞