Longest Continuous Increasing Subsequence

题目
Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).

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 {
    public int findLengthOfLCIS(int[] nums) {
        if(nums.length == 0) return 0;
        int[] f = new int[nums.length];
        f[0]  = 1;
        int max = 0;
        max = Math.max(max, f[0]);
        
        for(int i = 1; i < f.length; i++) {
            if(nums[i - 1] < nums[i])
                f[i] = f[i - 1] + 1;
            else
                f[i] = 1;
            max = Math.max(max, f[i]);
        }
        return max;
    }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 12,190评论 0 10
  • 此文针对IOS用户,如有安卓手机,请直接从软件安装部分开始阅读。 短视频或者声音诉说,越来越成为一种很流行的内容传...
    默默喜欢你阅读 5,689评论 9 8
  • 今天主要对flex进行重新说明以及补充,首先给大家介绍一下什么是flex布局:Flex 是 Flexible Bo...
    likeli阅读 2,593评论 0 0
  • (6) 我们起重班是个大班,全班26人,8个老师付、8个中专生、8个子弟,还有2个转业兵。年令、性格、资历、背景不...
    号子1113阅读 1,369评论 0 0

友情链接更多精彩内容