LeetCode 674. longest continuous increasing sequence

Topic links: https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/

Given an array of integers to unsorted, finding the longest and continuous incremental sequence.

Example 1:

Input: [1,3,5,4,7]
Output: 3
Explanation: longest continuous incremental sequence is [3,5], a length of 3.
Although [1,3,5,7] are ascending sequence, but it is not continuous, since 5 and 7 are separated in the primary array 4.
Example 2:

Input: [2,2,2,2,2]
Output: 1
Explanation: longest continuous incremental sequence of [2], a length of 1.
Note: the array length does not exceed 10000.

 1 int findLengthOfLCIS(int* nums, int numsSize){
 2     if(numsSize==0) return 0;
 3     int maxn=1,t=1;
 4     for(int i=1;i<numsSize;i++){
 5         if(nums[i]>nums[i-1]){
 6             t++;
 7             if(t>maxn) maxn=t;
 8         }else{
 9             t=1;
10         }
11     }
12     return maxn;
13 }

 

Guess you like

Origin www.cnblogs.com/shixinzei/p/11367380.html