首页 > 其他 > 详细

Leetcode 674 最长连续子序列

时间:2021-03-03 22:29:39      阅读:5      评论:0      收藏:0      [点我收藏+]

技术分享图片

  JAVA:

    public final int findLengthOfLCIS(int[] nums) {
        if (nums.length < 2) return nums.length;
        int len = nums.length, left = 0, right = 1, re = 0;
        while (left < len && right < len) {
            int currRe = 1;
            while (nums[right] > nums[left]) {
                currRe++;
                left++;
                right++;
                if (right == len) return Math.max(currRe, re);
            }
            if (currRe > re) re = currRe;
            left = right;
            right++;
        }
        return re;
    }

  JS:

/**
 * @param {number[]} nums
 * @return {number}
 */
var findLengthOfLCIS = function (nums) {
    let len = nums.length;
    if (len < 2) return len;
    let left = 0, right = 1, re = 0;
    while (right < len) {
        let currRe = 1;
        while (right < len && nums[right] > nums[left]) {
            left++;
            right++;
            currRe++;
        }
        re = re > currRe ? re : currRe;
        left=right;
        right++;
    }
    return re;
};

技术分享图片

 

Leetcode 674 最长连续子序列

原文:https://www.cnblogs.com/niuyourou/p/14477180.html

(0)
(0)
   
举报
评论 一句话评论(0
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号