leetcode 674 Longest Continuous Increasing Subsequence

原题是:

Given an unsorted array of integers, find the length of longest continuous increasing subsequence.

Example 1:
Input: [1,3,5,4,7]
Output: 3
Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3.
Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4.
Example 2:
Input: [2,2,2,2,2]
Output: 1
Explanation: The longest continuous increasing subsequence is [2], its length is 1.
Note: Length of the array will not exceed 10,000.

代码是:

class Solution(object):
    def findLengthOfLCIS(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums) == 0:
                return 0
        ans,curLength = 1, 1
        
        for i in xrange(len(nums)-1):
            
            if nums[i] < nums[i+1]:
                curLength = curLength + 1
                
            else:
                curLength = 1
            ans = max(ans,curLength)    
        
        return ans

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 14,357评论 0 33
  • 这一周我干了很多事,如:练字、阅读、配趣配音、看电影、写数学作业、背诵诗歌、洗碗、拖地、整理房间,等等…… 咱们先...
    小溪流18王家硕阅读 3,596评论 2 1
  • 在一辆火车上,一个中年男人正在打电话,他文件夹里的几张纸不小心掉了出来。一个14岁的男孩看到之后,帮他把东西捡了起...
    刘淼阅读 9,579评论 19 58
  • 人人都是一方神秘的磁场,吸引着类似气质的同伴。遇到什么样的人,也侧面印证着你是什么样的人。每一个走进你生命的人,都...
    盏茶轻茗阅读 1,702评论 0 1
  • 今天和燕姐姐去必胜客吃了披萨和牛排,还点了下午茶。吃的很饱,不过也吃了很多钱。其实挺开心的并不用怎么说。后来她说去...
    太阳CC阅读 1,441评论 0 0

友情链接更多精彩内容