1 Star 0 Fork 0

luobg01/PFJ_coding

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
code031_lengthOfLIS.h 1.36 KB
一键复制 编辑 原始数据 按行查看 历史
luobg01 提交于 2023-11-24 08:34 . 增加最长递增子序列问题
//
// Created by 罗炳国 on 2023/11/16.
//
#ifndef PFJ_CODE031_LENGTHOFLIS_H
#define PFJ_CODE031_LENGTHOFLIS_H
#include "commonHeader.h"
/**
* 给你一个整数数组 nums ,找到其中最长严格递增子序列的长度。
* 子序列 是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列。
* https://leetcode.cn/problems/longest-increasing-subsequence/description/
**/
class code031_lengthOfLIS {
public:
// O(N2)
int lengthOfLIS(vector<int>& nums) {
int N = nums.size(), ans = 0;
// 必须以nums[i]结尾的字串,最长递增子序列是多长
vector<int> dp(N, 0);
for (int i = 0; i < N; i++) {
int maxVal = 0;
for (int j = 0; j < i; j++) {
if (nums[j] < nums[i])
maxVal = max(dp[j], maxVal);
}
dp[i] = maxVal + 1;
ans = max(ans, dp[i]);
}
return ans;
}
// NlgN
int lengthOfLISPlus(vector<int>& nums) {
int N = nums.size();
//ends[i]表示长度为i+1的最长子序列存在,且当前形成i+1长度的子序列中最小以ends[i]结尾
vector<int> ends(N, 0);
for (int i = 0; i < N; i++) {
}
}
};
#endif//PFJ_CODE031_LENGTHOFLIS_H
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/luobg01/pfj_coding.git
git@gitee.com:luobg01/pfj_coding.git
luobg01
pfj_coding
PFJ_coding
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385