当前位置 : 主页 > 网页制作 > HTTP/TCP >

最长连续递增子串

来源:互联网 收集:自由互联 发布时间:2021-06-16
题目链接:https://leetcode.com/problems/longest-continuous-increasing-subsequence/description/ class Solution { public : int findLengthOfLCIS(vector int nums) { int n = nums.size(); if (n= 1 ) return n; int res = 1 , len= 1 ; for ( int

题目链接:https://leetcode.com/problems/longest-continuous-increasing-subsequence/description/

class Solution {
public:
    int findLengthOfLCIS(vector<int>& nums) {
        int n = nums.size();
        if(n<=1) return n;
        int res = 1, len=1;
        for(int i=1; i<n; i++){
            if(nums[i] > nums[i-1]) len+=1;
            else len = 1;
            res = max(len, res);
        }
        return res;
    }
};
 
网友评论