当前位置:网站首页>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 明后两天大到爆雨
边栏推荐
猜你喜欢

Shell learning record (II)

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

vs2015+PCL1.8.1+qt5.12-----(1)

Abnova anti GBA monoclonal antibody solution

One minute to understand the difference between synchronous, asynchronous, blocking and non blocking

图形渲染管线

关于VS scanf出现‘scanf‘: This function or variable may be unsafe. Consider usi问题的解决方法

Ndk20b ffmpeg4.2.2 compilation and integration

jenkins汉化及汉化无效解决方案

安装了Visual Studio 2013 Redistributable,mysql还是安装失败
随机推荐
Shell curl execution script, with passed parameters and user-defined parameters
Redis-链表
前置++,后置++与前置--与后置--(++a,a++与--a,a--)
NDK20b FFmpeg4.2.2 编译和集成
反向输出一个整数
连接投影仪
Record a weird picture upload problem
静态库动态库的使用
Shell learning record (I)
Calibration...
shell学习记录(四)
Chemical properties and application of trypsin
轻轻松松理解指针
一分钟了解同步、异步、阻塞和非阻塞的区别
Weishi camera display
LeetCode 31 ~ 40
Convert Weishi camera pictures
Steps of program compilation precompile compilation assembly connection
Gun make (7) execute make
shell学习记录(二)