链接:https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/
代码:
class Solution { public: int findLengthOfLCIS(vector<int>& nums) { int n = nums.size(); if(n == 0) return 0; if(n == 1) return 1; int a[n]; for(int i= 0; i < n; i++) { if(i == 0) a[i] = 1; else a[i] = nums[i]-nums[i-1] > 0 ? 1 : 0; } // debug for(int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; int res = 1; int cur = 0; for(int i = 0; i < n; i++) { if(a[i] == 1) { cur++; res = max(res, cur); } else cur = 1; } return res; } };
思路:求增量然后找到最长 1 串即可。