longest-continuous-increasing-subsequence

Longest Continuous Increasing Subsequence – LeetCode 674

Problem

Description

Given an unsorted array of integers, find the length of longest continuous increasing subsequence (subarray).

Answer

Better

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
public:
int findLengthOfLCIS(vector<int>& nums) {
if(!nums.size())
return 0;
unsigned cnt = 1, Max = cnt;
for(unsigned i = 1; i < nums.size(); ++i){
if(nums[i] > nums[i-1])
Max = max(Max, ++cnt);
else
cnt = 1;
}
return Max;
}
};

思路

正常的单次遍历统计。时间复杂度$O(n)$,空间复杂度$O(1)$。
耗时$8$ ms,排名$2.48\%$

Better

思路

还没看到更好的思路