问题描述
解题思路
dp[i]
表示以nums[i - 1]
结尾的最长连续递增子序列长度;
递推关系为:
if (nums[i - 1] > nums[i - 2])
dp[i] = dp[i - 1] + 1;
代码
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;
}
};
标签:nums,674,递增,continuous,int,subsequence,序列,dp
From: https://www.cnblogs.com/zwyyy456/p/16841679.html