我的js算法爬坑之旅-最长连续递增序列

278 阅读1分钟

第一百零七天:力扣674题,最长连续递增序列

地址:leetcode-cn.com/problems/lo…

思路:双指针

var findLengthOfLCIS = function(nums) {
  let max = 0;
  const n = nums.length;
  if(n == 1)
  {
    return 1;
  }
  for(let i = 0,j = 1;i < n,j < n;i++,j++)
  {
    let res = 1;
    while(nums[j] > nums[i] && j < n)
    {
      res++;
      j++;
      i++;
    }
    max = Math.max(res,max);
  }
  return max;
};

执行用时:100 ms, 在所有 JavaScript 提交中击败了15.54%的用户

内存消耗:39.1 MB, 在所有 JavaScript 提交中击败了25.17%的用户