当前位置:网站首页>Longest increasing subsequence
Longest increasing subsequence
2022-06-11 02:57:00 【ambition_ forever】
package LongestIncrSub;
import java.util.Arrays;
import java.util.HashSet;
/**
* Function description
* The longest increasing subsequence
*/
public class Main {
public static void getLongestIncrSub(int[] arr) {
int len = arr.length;
int[] dp = new int[len];
int[] res = new int[len];
Arrays.fill(dp, 1);
Arrays.fill(res, 0);
int maxNum = arr[0];
int maxDp = 0;
for (int i = 0; i < len; i++) {
maxNum = Math.max(maxNum, arr[i]);
for (int j = i; j >= 0; j--) {
if (arr[i] > arr[j]) {
dp[i] = 1 + dp[j];
res[i] = arr[j];
maxDp = Math.max(maxDp, dp[i]);
break;
}
}
}
HashSet<Integer> resSet = new HashSet<>();
for (int redI : res) {
if (redI == 0) {
continue;
边栏推荐
猜你喜欢
![【长时间序列预测】Aotoformer 代码详解之[3]模型整体架构分析](/img/77/30215c363ae8a1324db1cbcaa5324b.png)
【长时间序列预测】Aotoformer 代码详解之[3]模型整体架构分析

Arduino Uno接JQ8900-16p语音播报模块

弄懂了采矿业与碳中和的逻辑,就读懂了矿区无人驾驶的千亿市场

Uni app - one click access to user information

【大咖秀】博睿数据眼中的AIOps,选择正确的赛道正确的人

Limiting visibility of symbols when linking shared libraries

Live broadcast! Feature matching of orb-slam3 series (mlpnp, word bag model, etc.).
![[C language classic]: inverted string](/img/f3/e6f37b852d22d395314628b73c9be3.jpg)
[C language classic]: inverted string

How to add cookie pop-up window in WordPress website (without plug-in)
![[189. rotation array]](/img/cc/0da616ad9adc9c9d352e54f58dbe41.png)
[189. rotation array]
随机推荐
Will your company choose to develop data center?
【189. 轮转数组】
同一个用户的两次请求SessionId竟然不一致-----记录问题
Common vocabulary of software testing English
Xampp is used under M1 chip, and the installation extension error
[189. rotation array]
Istio安装与使用
CPT 102_LEC 15
jdbc工具類的問題
【冒泡排序的实现】
CPT 102_LEC 16
蓝桥杯_小蓝吃糖果_鸽巢原理 / 抽屉原理
Necessity for banks to choose electronic bidding procurement
怎样简洁明了地说清楚产品需求?
Baidu submits sitemap to prompt the solution of "index type is not handled"
CPT 102_LEC 17
How to add cookie pop-up window in WordPress website (without plug-in)
CPT 102_LEC 13-14
軟件測試英語常見詞匯
error exepected identifier before ‘(‘ token, grpc 枚举类编译错误