zoukankan      html  css  js  c++  java
  • 20210124 最长连续递增序列

    给定一个未经排序的整数数组,找到最长且 连续递增的子序列,并返回该序列的长度。
    
    连续递增的子序列 可以由两个下标 l 和 r(l < r)确定,如果对于每个 l <= i < r,都有 nums[i] < nums[i + 1] ,那么子序列 [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]] 就是连续递增子序列。
    
     
    
    示例 1:
    
    输入:nums = [1,3,5,4,7]
    输出:3
    解释:最长连续递增序列是 [1,3,5], 长度为3。
    尽管 [1,3,5,7] 也是升序的子序列, 但它不是连续的,因为 5 和 7 在原数组里被 4 隔开。 
    示例 2:
    
    输入:nums = [2,2,2,2,2]
    输出:1
    解释:最长连续递增序列是 [2], 长度为1。
    
    来源:力扣(LeetCode)
    链接:https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence
    著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
    public int findLengthOfLCIS(int[] nums) {
    
        }

    思路:定义一个int 再遍历数组 每次升序int+1 直到遍历出最大值

      

     public int findLengthOfLCIS(int[] nums) {
            int s =1;
            int max=1;
            int len = nums.length;
            if (len==0)return 0;//以防入参空值
            for (int i = 0; i < len-1 ; i++) {
                if (nums[i]<nums[i+1]){
                    s++;
                    max=Math.max(s,max);
                }else {
                    s=1;   
                }
            }
            return max;
        }
  • 相关阅读:
    [笔迹]java范型
    转:APNS设置
    orientation in a UIView add to a UIWindow
    no password for ssh
    webservice soap
    set the region for all annotation
    iOS与Java服务器GZip压缩问题【转】
    useful commands for Mac / iOS
    textView使用总结
    总结(不断更新)
  • 原文地址:https://www.cnblogs.com/hbhb/p/14322452.html
Copyright © 2011-2022 走看看