当前位置:网站首页>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 明后两天大到爆雨
边栏推荐
- Visual studio 2013 redistributable is installed, but MySQL installation fails
- Convert Weishi camera pictures
- Chrome浏览器开发者工具使用
- Raspberry pie + AWS IOT Greengrass
- Reverse output an integer
- CVPR2022 | 长期行动预期的Future Transformer
- Gun make (7) execute make
- 如何使用命令将文件夹中的文件名(包括路径)写入到txt文件中
- 如何制定一个可实现的年度目标?
- Scala 基础 (二):变量和数据类型
猜你喜欢
随机推荐
论文阅读 Exploring Temporal Information for Dynamic Network Embedding
Convert Weishi camera pictures
Differences and functions of TOS cos DSCP
Playful girl wangyixuan was invited to serve as the Promotion Ambassador for the global finals of the sixth season perfect children's model
Cs144 environment configuration
Chrome浏览器开发者工具使用
Tcp网络通信中各个状态的含义
Redis-SDS
前置++,后置++与前置--与后置--(++a,a++与--a,a--)
Application and chemical properties of elastase
A solution to cross domain problems
Chinese and English instructions of collagen enzyme Worthington
How to efficiently complete daily tasks?
cv==biaoding---open----cv001
Differences and functions of export set env in makefile
Visual studio 2013 redistributable is installed, but MySQL installation fails
CyCa children's physical etiquette Yueqing City training results assessment successfully concluded
宁要一个完成,不要千万个开始(转载自豆瓣)
如何使用命令将文件夹中的文件名(包括路径)写入到txt文件中
求n乘阶之和









