当前位置:网站首页>leetcode 300. Longest increasing subsequence (medium)
leetcode 300. Longest increasing subsequence (medium)
2022-06-26 02:13:00 【InfoQ】
One 、 The main idea of the topic
- 1 <= nums.length <= 2500
- -104 <= nums[i] <= 104
- You can reduce the time complexity of the algorithm to O(n log(n)) Do you ?
Two 、 Their thinking
3、 ... and 、 How to solve the problem
3.1 Java Realization
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;
}
}
Four 、 Summary notes
- 2022/6/25 It will rain heavily in the next two days
边栏推荐
猜你喜欢

FPGA实现图像二值形态学滤波——腐蚀膨胀

SDRAM controller -- implementation of arbitration module

V4L2+QT视频优化策略

论文阅读 Exploring Temporal Information for Dynamic Network Embedding

General introduction to gun make (2)

Ardiuno智能电蚊拍

OA process editing

Abnova anti GBA monoclonal antibody solution

【js】免费api判断节假日、工作日和周六日

Disruptor (I) sequence
随机推荐
Implementation of image binary morphological filtering based on FPGA -- Corrosion swelling
FPGA实现图像二值形态学滤波——腐蚀膨胀
深度好文:什么是超网 Supernetting?
Timer case
表达式的动态解析和计算,Flee用起来真香
樹莓派 + AWS IoT Greengrass
【js】免费api判断节假日、工作日和周六日
Markov decision process (MDP): Blackjack problem (mc-es)
Create OpenGL window
Tab switch
Redis linked list
图形渲染管线
Redis-SDS
Connecting the projector
Chrome browser developer tool usage
shell学习记录(四)
一分钟了解同步、异步、阻塞和非阻塞的区别
Unexpected output super efficiency SBM model matlab code
Shell learning record (III)
Simplex method (1)