当前位置:网站首页>20220528动态规划:最长递增子序列
20220528动态规划:最长递增子序列
2022-08-09 02:37:00 【丿SeeYouAgain】
题目描述:给你一个整数数组 nums ,找到其中最长严格递增子序列的长度。子序列 是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列。
编码实现:
public int lengthOfLIS(int[] nums) {
if (null == nums){
return 0;
}
int size = nums.length;
if (size <= 1){
return 1;
}
int tmp[] = new int[size];
int length = 1, index = 0;
tmp[index] = nums[0];
for (int i = 1; i < size; i++) {
if (nums[i] > tmp[index]) {
tmp[++index] = nums[i];
length++;
} else if (nums[i] < tmp[index]) {
if (index == 0) {
tmp[index] = nums[i];
} else {
for (int j = index; j >= 0; j--) {
if (j == 0 || tmp[j - 1] < nums[i]) {
tmp[j] = nums[i];
break;
}
}
}
}
}
return length;
}
边栏推荐
猜你喜欢

Solve the Final Fantasy 13-2 Clock Puzzle with DFS
![[Redis] The core principle of master-slave replication](/img/42/6b0f511d3bcf4b951b556408b021c4.png)
[Redis] The core principle of master-slave replication

MT4 / MQ4L entry to the master of EA tutorial lesson two (2) - - MQL language commonly used function account information commonly used functions

工作小计 rtcp的length和网络字节序

Line segment tree of knowledge

评估深度学习模型的指标:混淆矩阵、准确率、精确率和召回率

边缘计算的三个关键好处

Electromagnetic radiation safety standards and detection methods

帮助安全红队取得成功的11条建议

【电商运营】不知道怎么做网站优化?这里有你需要知道的一切!
随机推荐
The building had been registry cluster, load balancing
评估深度学习模型的指标:混淆矩阵、准确率、精确率和召回率
Composer usage record
Postman接口测试【官网】最新版本 安装及使用入门教程
Appium常用操作及H5页面元素定位
xml引配置文件
2.1-----27. Remove elements
【网络教程】IPtables官方教程--学习笔记3
OJ:L3-001 凑零钱 DFS
JS 实现千分位分隔符
全志通过fastboot烧写boot.img
17.flink Table Api基础概念讲解
边缘计算的三个关键好处
全志平台双路LVDS配置
如何最大限度地减少企业受到供应链攻击的风险
2022 Eye Health Brand Franchise Exhibition, Beijing Vision Care Exhibition, China Ophthalmology Technology Summit
My thoughts on software development
Line segment tree of knowledge
工具类:base64格式的数据与本地文件的相互转换
【电商运营】不知道怎么做网站优化?这里有你需要知道的一切!