LeetCode Solutions

674. Longest Continuous Increasing Subsequence

Time: $O(n)$

Space: $O(1)$

			

class Solution {
 public:
  int findLengthOfLCIS(vector<int>& nums) {
    int ans = 0;

    for (int l = 0, r = 0; r < nums.size(); ++r) {
      if (r > 0 && nums[r] <= nums[r - 1])
        l = r;
      ans = max(ans, r - l + 1);
    }

    return ans;
  }
};
			

class Solution {
  public int findLengthOfLCIS(int[] nums) {
    int ans = 0;

    for (int l = 0, r = 0; r < nums.length; ++r) {
      if (r > 0 && nums[r] <= nums[r - 1])
        l = r;
      ans = Math.max(ans, r - l + 1);
    }

    return ans;
  }
}
			

class Solution:
  def findLengthOfLCIS(self, nums: List[int]) -> int:
    ans = 0
    j = 0

    for i in range(len(nums)):
      if i > 0 and nums[i] <= nums[i - 1]:
        j = i
      ans = max(ans, i - j + 1)

    return ans