当前位置:网站首页>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;
}
边栏推荐
- C#计算SHA1加密和base64编码
- VS2019编译boost_1_79,生成32位和64位静态库
- [LeetCode305周赛] 6136. 算术三元组的数目,6139. 受限条件下可到达节点的数目,6137. 检查数组是否存在有效划分,6138. 最长理想子序列
- Jenkins environment deployment, (packaging, publishing, deployment, automated testing)
- Force buckled brush problem record 7.1 -- -- -- -- -- 707. The design list
- 高性能 MySQL(十二):分区表
- MT4/MQL4 Getting Started to Mastering EA Tutorial Lesson 1 - MQL Language Common Functions (1) OrderSend() Function
- 继承 Inheritance
- 独立机器连接cdh的spark集群,远程提交任务(绝对可以成功,亲测了n遍)
- Jenkins的环境部署,(打包、发布、部署、自动化测试)
猜你喜欢
随机推荐
LintCode 146. 大小写转换 II
全志通过fastboot烧写boot.img
[Redis] The core principle of master-slave replication
嵌入式设备驱动开发
[LeetCode84双周赛] [模拟] 6174. 任务调度器 II,[贪心&数学] 6144. 将数组排序的最少替换次数
Summary of pytorch related knowledge points
Flume (四) --------- Flume 企业开发案例
危化企业双预防机制数字化建设工作要求
从0开始搭建自动化测试框架之PO分层架构
SQLite切换日志模式优化
工具类:base64格式的数据与本地文件的相互转换
微信公众号跳转小程序 wx-open-launch-weapp (最全指南及坑)
MT4 / MQ4L entry to the master of EA tutorial lesson two (2) - - MQL language commonly used function account information commonly used functions
Json之JArray的使用方法
A40i gxl3680 ts_print报错:tslib: Selected device is not a touchscreen (must support ABS and KEY event
Open3D 计算点云的均值(质心)与协方差
Open3D 均匀采样
Processing Point Clouds
基于JMF视频聊天
My thoughts on software development