代码随想录day43 300.最长递增子序列 674. 最长连续递增序列 718. 最长重复子数组
代码随想录
class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
int size = nums.size();
if (size == 1) {
return 1;
}
vector<int> dp(size, 1);
int res = 1;
for (int i = 1; i < size; i++) {
for (int j = 0; j < i; j++) {
if (nums[j] < nums[i]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
res = res < dp[i] ? dp[i] : res;
}
return res;
}
};
代码随想录
class Solution {
public:
int findLengthOfLCIS(vector<int>& nums) {
int size = nums.size();
if (size == 1) {
return 1;
}
vector<int> dp(size, 1);
int res = 1;
for (int i = 1; i < size; i++) {
if (nums[i - 1] < nums[i]) {
dp[i] = dp[i - 1] + 1;
}
res = res < dp[i] ? dp[i] : res;
}
return res;
}
};
代码随想录
class Solution {
public:
int findLength(vector<int>& nums1, vector<int>& nums2) {
int size1 = nums1.size();
int size2 = nums2.size();
vector<vector<int>> dp(size1 + 1, vector<int>(size2 + 1, 0));
int res = 0;
for (int i = 1; i <= size1; i++) {
for (int j = 1; j <= size2; j++) {
if (nums1[i - 1] == nums2[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
}
res = res < dp[i][j] ? dp[i][j] : res;
}
}
return res;
}
};