题目来源:https://leetcode.cn/problems/longest-continuous-increasing-subsequence/description/
C++题解:贪心算法。把所有元素遍历一遍,比较它与上个数的大小,大的话更新长度tmp,小的话初始化长度tmp,并与最大连续递增子序列长度len进行比较。
class Solution {
public:int findLengthOfLCIS(vector<int>& nums) {int n = nums.size();if(n == 1) return 1;int len = 1, tmp = 1;for(int i = 1; i < n; i++) {if(nums[i] > nums[i-1]) tmp++;else {len = max(len, tmp);tmp = 1;}}len = max(len, tmp);return len;}
};