Description Link to heading
674.longest-continuous-increasing-subsequence
Solution Link to heading
dp[i]
denotes the length of longest continuous increasing subsequence ending with nums[i - 1]
;
Recurrence formula:
if (nums[i - 1] > nums[i - 2])
dp[i] = dp[i - 1] + 1;
Code Link to heading
class Solution {
public:
int findLengthOfLCIS(vector<int> &nums) {
vector<int> dp(nums.size() + 1, 1);
int m = 1;
for (int i = 2; i <= nums.size(); i++) {
if (nums[i - 1] > nums[i - 2])
dp[i] = dp[i - 1] + 1;
if (dp[i] > m)
m = dp[i];
}
return m;
}
};