当前位置:网站首页>leetcode 300. Longest Increasing Subsequence 最长递增子序列 (中等)
leetcode 300. Longest Increasing Subsequence 最长递增子序列 (中等)
2022-06-26 00:33:00 【InfoQ】
一、题目大意
- 1 <= nums.length <= 2500
- -104 <= nums[i] <= 104
- 你能将算法的时间复杂度降低到 O(n log(n)) 吗?
二、解题思路
三、解题方法
3.1 Java实现
public class Solution {
public int lengthOfLIS(int[] nums) {
int n = nums.length;
if (n <= 1) {
return n;
}
int[] dp = new int[n];
for (int i = 0; i < n; i++) {
dp[i] = 1;
}
int ret = dp[0];
for (int i = 0; i < n; i++) {
for (int j = 0; j < i; j++) {
if (nums[i] > nums[j]) {
dp[i] = Math.max(dp[i], dp[j] + 1);
}
}
ret = Math.max(dp[i], ret);
}
return ret;
}
}
四、总结小记
- 2022/6/25 明后两天大到爆雨
边栏推荐
- Keda 2.7.1 brief analysis of scaledjob code
- Tengwenze, a hot-blooded boy, was invited to serve as the image ambassador of the global finals of the sixth season perfect children's model
- Gun make (3) Rules for makefile
- vscode调试时提示更新到最新调试版本
- Calibration...
- Reverse output an integer
- Prometeus 2.33.0 新特性
- It's better to finish one than start thousands of times (reprinted from Douban)
- Weishi camera display
- Tarte aux framboises + AWS IOT Greengrass
猜你喜欢

Disruptor (I) sequence

Abnova anti GBA monoclonal antibody solution

Sunshine boy chenhaotian was invited to be the spokesperson for the global finals of the sixth season perfect children's model

安装了Visual Studio 2013 Redistributable,mysql还是安装失败

树莓派 + AWS IoT Greengrass

Redis7.0 installation steps

Exploring temporary information for dynamic network embedding

On the difference between strlen and sizeof

Getting to know OpenGL

Scala 基础 (二):变量和数据类型
随机推荐
vs2015+PCL1.8.1+qt5.12-----(1)
UN make (6) conditional execution of makefile
工作一年闲记
jenkins汉化及汉化无效解决方案
Steps of program compilation precompile compilation assembly connection
shell curl 执行脚本,带传参数,自定义参数
V4L2+QT视频优化策略
socket demo01
LeetCode 31 ~ 40
連接投影儀
Prompt to update to the latest debug version during vscode debugging
Redis-链表
The answer skills and examples of practical cases of the second construction company are full of essence
其他代码,,vt,,,k
创建OpenGl窗口
将weishi相机图片进行转换
Pointnet/Pointnet++学习
Shell learning record (II)
宁要一个完成,不要千万个开始(转载自豆瓣)
readv & writev