Leetcode 674. 最长连续递增序列 (贪心思想)

这里的子序列一定要求连续,所以可以用贪心的思想解决,比较简单。

class Solution {
public:
    int findLengthOfLCIS(vector<int>& nums) {
        if(nums.size()==0) return 0;
        int count= 1, tmp = nums[0], res= 1;
        for(auto num:nums){
            if(num>tmp) count++;
            else count=1;
            tmp = num;
            res = max(count,res);
        }
        return res;
    }
};

猜你喜欢

转载自blog.csdn.net/wwxy1995/article/details/113115167
今日推荐