yifanzheng / leetcode-java

数据结构与算法学习
MIT License
3 stars 0 forks source link

674. 最长连续递增序列 #5

Open yifanzheng opened 3 years ago

yifanzheng commented 3 years ago

leetCode 地址:674. 最长连续递增序列

题解

贪心

public int findLengthOfLCIS(int[] nums) {
   int len = nums.length;
   if (len <= 1) {
     return len;
   }
   int lp = 0, rp = 1;
   int maxLen = 0;
   while (lp < len && rp < len) {
      if (nums[rp-1] >= nums[rp]) {
        lp = rp;
      }
      rp++;
      maxLen = Math.max(maxLen, rp - lp);
   }

   return maxLen;
}