The longest continuous increasing sequence of 2021.

Problem:
Given an unsorted integer array, find the longest and continuously increasing subsequence, and return the length of the sequence.

The continuously increasing subsequence can be determined by two subscripts l and r (l <r). If for each l <= i <r, there is nums[i] <nums[i + 1], then the subsequence [ nums[l], nums[l + 1], …, nums[r-1], nums[r]] are successively increasing subsequences.

Example 1:
Input: nums = [1,3,5,4,7]
Output: 3
Explanation: The longest continuous increasing sequence is [1,3,5], and the length is 3.
Although [1,3,5,7] is also an ascending subsequence, it is not continuous, because 5 and 7 are separated by 4 in the original array.
Example 2:
Input: nums = [2,2,2,2,2]
Output: 1
Explanation: The longest continuous increasing sequence is [2], and the length is 1.
Code:

class Solution {
    
    
public:
    int findLengthOfLCIS(vector<int>& nums) {
    
    
        int size=nums.size(),res=1,temp=1;
        if(size<=1){
    
    return size;}
        for(int i=1;i<size;i++)
        {
    
    
            if(nums[i]>nums[i-1])
            {
    
    
                temp++;
            }
            else
            {
    
    
                res=max(temp,res);temp=1;
            }
        }
        return max(temp,res);
    }
};

Guess you like

Origin blog.csdn.net/weixin_45780132/article/details/113066135