Leetcode 674. Longest Continuous Increasing Subsequence

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  简书

1. Description

Longest Continuous Increasing Subsequence

2. Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public:
int findLengthOfLCIS(vector<int>& nums) {
int max_length = 0;
if(nums.size() <= 1) {
return nums.size();
}
int length = 1;
for(int i = 1; i < nums.size(); i++) {
if(nums[i] > nums[i - 1]) {
length++;
}
else {
length = 1;
}
max_length = max(max_length, length);
}
return max_length;
}
};

Reference

  1. https://leetcode.com/problems/longest-continuous-increasing-subsequence/description/
如果有收获,可以请我喝杯咖啡!