当前位置:网站首页>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 明后两天大到爆雨
边栏推荐
- 树莓派 + AWS IoT Greengrass
- Use of static library and dynamic library
- Gun make (3) Rules for makefile
- LeetCode 41 ~ 50
- Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Hangzhou
- VTK initialization code learning 1
- Keda 2.7.1 brief analysis of scaledjob code
- Other codes,, VT,,, K
- 樹莓派 + AWS IoT Greengrass
- 【js】免费api判断节假日、工作日和周六日
猜你喜欢

About vs scanf, 'scanf' appears: this function or variable may be unsafe Solutions to the problem of consumer usi

cv==biaoding---open----cv001

Getting to know OpenGL

Wanglaoji pharmaceutical's public welfare activity of "caring for the most lovely people under the scorching sun" was launched in Hangzhou

通俗易懂C语言关键字static

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

Pointnet/Pointnet++学习

Tarte aux framboises + AWS IOT Greengrass

一分钟了解同步、异步、阻塞和非阻塞的区别

jenkins汉化及汉化无效解决方案
随机推荐
About vs scanf, 'scanf' appears: this function or variable may be unsafe Solutions to the problem of consumer usi
readv & writev
-- EGFR FISH probe solution
Prompt to update to the latest debug version during vscode debugging
Redis-链表
反向输出一个整数
Energetic girl wangyujie was invited to be the spokesperson for the global finals of the sixth season perfect children's model
Codecraft-17 and Codeforces Round #391 (Div. 1 + Div. 2, combined) D. Felicity‘s Big Secret Revealed
@Query 疑难杂症
On the difference between strlen and sizeof
buffer
How to efficiently complete daily tasks?
螺旋矩阵
Tarte aux framboises + AWS IOT Greengrass
Raspberry pie + AWS IOT Greengrass
vs2015+PCL1.8.1+qt5.12-----(1)
Disruptor(一)Sequence
SDRAM控制器——仲裁模块的实现
Weishi camera display
It's better to finish one than start thousands of times (reprinted from Douban)