美文网首页leetcode和算法----日更
leetcode 674 最长连续递增序列

leetcode 674 最长连续递增序列

作者: Arsenal4ever | 来源:发表于2020-02-18 23:34 被阅读0次

    说是数组,但是感觉贪心更合适,和跳跃数组也有点像。维护递增长度和最大递增长度即可求出结果!!!

    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
    

    相关文章

      网友评论

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

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