Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).
Example 1:
Input:
Output: 3
Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3.
Even though [1,3,5,7] is also an increasing subsequence, it's not a continuous one where 5 and 7 are separated by 4.
Example 2:
Input:
Output: 1
Explanation: The longest continuous increasing subsequence is [2], its length is 1.
Note: Length of the array will not exceed 10,000.
int findLengthOfLCIS(int* nums, int numsSize)
{
if(NULL == nums || 0 == numsSize )
return 0;
/*用于统计最大连续子数组长度*/
int max = 1;
/*cnt是统计的当前连续子数组长度*/
int cnt = 1;
for(int i = 1;i < numsSize;i++)
{
if(nums[i] > nums[i-1])
{
/*cnt初始值为1,因为存在大小关系至少需要两个,后续每存在一个大的,加1*/
cnt += 1;
}
else
{
max = (max > cnt) ? max:cnt;
/*重置cnt,开始新一轮统计*/
cnt = 1;
}
}
/*如果数组所有元素均递增,不进入else分支,在此添加判断*/
max = (max > cnt) ? max:cnt;
return max;
}