Longest Continuous Increasing Subsequence
Problem
Given an unsorted array of integers nums
, return the length of the longest continuous increasing subsequence (i.e. subarray). The subsequence must be strictly increasing.
A continuous increasing subsequence is defined by two indices l
and r
(l < r
) such that it is [nums[l], nums[l + 1], ..., nums[r - 1], nums[r]]
and for each l <= i < r
, nums[i] < nums[i + 1]
.
Constraints
1 <= nums.length <= 104
-109 <= nums[i] <= 109
Solution
The problem Longest Continuous Increasing Subsequence
can be solved by checking each continuous increasing subsequence in the array and finding the longest one.
Implementation
class Solution
{
public:
int findLengthOfLCIS(vector<int> &nums)
{
nums.push_back(INT_MIN);
int idx = 0, len = 1;
for (int i = 1; i < nums.size(); i++)
{
if (nums[i] <= nums[i - 1])
{
len = max(len, i - idx);
idx = i;
}
}
return len;
}
};