当前位置:网站首页>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 明后两天大到爆雨
边栏推荐
- Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) C. Felicity is Coming!
- 跨域问题的一种解决方案
- Steps of program compilation precompile compilation assembly connection
- keda 2.7.1 scaledJob 代码简要分析
- Command of gun make (4) rule
- Connecting the projector
- 输入3个整数,从大到小输出出来
- 关于VS scanf出现‘scanf‘: This function or variable may be unsafe. Consider usi问题的解决方法
- SDRAM控制器——添加读写FIFO
- 连接投影仪
猜你喜欢
Tarte aux framboises + AWS IOT Greengrass
Abnova CMV CISH probe solution
vscode调试时提示更新到最新调试版本
Getting to know OpenGL
shell学习记录(二)
NDK20b FFmpeg4.2.2 编译和集成
Differences and functions of TOS cos DSCP
Abnova CSV monoclonal antibody solution
CyCa children's physical etiquette Yueqing City training results assessment successfully concluded
A lost note for konjaku beginner
随机推荐
How to set achievable medium - and long-term goals?
vtk初始化代码学习1
Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Hangzhou
求n乘阶之和
Detailed explanation of WiFi related knowledge
Sweet girl lisixia was invited to be the little host of the global finals of the sixth season perfect child model
Spiral matrix
@Query 疑难杂症
螺旋矩阵
The answer skills and examples of practical cases of the second construction company are full of essence
Find the multiplication order of n
Three factors affecting personal growth
Shell learning record (IV)
初识Opengl
Exploring temporary information for dynamic network embedding
shell学习记录(二)
安装了Visual Studio 2013 Redistributable,mysql还是安装失败
论文阅读 Exploring Temporal Information for Dynamic Network Embedding
One minute to understand the difference between synchronous, asynchronous, blocking and non blocking
vscode调试时提示更新到最新调试版本