美文网首页LeetCode
674. 最长连续递增序列

674. 最长连续递增序列

作者: cptn3m0 | 来源:发表于2019-03-20 10:50 被阅读0次

伪装成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

相关文章

网友评论

    本文标题:674. 最长连续递增序列

    本文链接:https://www.haomeiwen.com/subject/pqxzmqtx.html