lc 最长连续递增序列

链接: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;
    }
};
View Code

思路:求增量然后找到最长 1 串即可。

posted on 2020-05-22 23:52  FriskyPuppy  阅读(162)  评论(0编辑  收藏  举报

导航