当前位置:网站首页>LeetCode 300. Daily question of the longest increasing subsequence
LeetCode 300. Daily question of the longest increasing subsequence
2022-07-07 16:58:00 【@Little safflower】
Problem description
Give you an array of integers nums , Find the length of the longest strictly increasing subsequence .
Subsequence Is a sequence derived from an array , Delete ( Or do not delete ) Elements in an array without changing the order of the rest . for example ,[3,6,2,7] It's an array [0,3,1,6,2,2,7] The subsequence .
Example 1:Input :nums = [10,9,2,5,3,7,101,18]
Output :4
explain : The longest increasing subsequence is [2,3,7,101], So the length is 4 .
Example 2:Input :nums = [0,1,0,3,2,3]
Output :4
Example 3:Input :nums = [7,7,7,7,7,7,7]
Output :1
Tips :
1 <= nums.length <= 2500
-104 <= nums[i] <= 104source : Power button (LeetCode)
link :https://leetcode.cn/problems/longest-increasing-subsequence
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
Java
class Solution {
public int lengthOfLIS(int[] nums) {
int n = nums.length;
if(n == 1) return 1;
int[] dp = new int[n];
dp[0] = 1;
int ans = 0;
for(int i = 1;i < n;i++){
dp[i] = 1;
for(int j = 0;j < i;j++){
if(nums[j] < nums[i]){
dp[i] = Math.max(dp[i],dp[j] + 1);
}
}
ans = Math.max(ans,dp[i]);
}
return ans;
}
}
边栏推荐
- Laravel changed the session from file saving to database saving
- [summary of knowledge] summary of notes on using SVN in PHP
- logback. XML configure logs of different levels and set color output
- QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建
- 谈谈 SAP 系统的权限管控和事务记录功能的实现
- 正在准备面试,分享面经
- LeetCode-SQL第一天
- Prediction - Grey Prediction
- Pisa-Proxy SQL 解析之 Lex & Yacc
- 预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
猜你喜欢
随机推荐
Opencv personal notes
Advanced C language -- function pointer
正在准备面试,分享面经
【医学分割】attention-unet
The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
Talk about the realization of authority control and transaction record function of SAP system
记录Servlet学习时的一次乱码
【MySql进阶】索引详解(一):索引数据页结构
Sort out several important Android knowledge and advanced Android development interview questions
面试题 01.02. 判定是否互为字符重排-辅助数组算法
Personal notes of graphics (2)
LeetCode 1981. 最小化目标值与所选元素的差 每日一题
Imitate the choice of enterprise wechat conference room
【DesignMode】模板方法模式(Template method pattern)
Interface oriented programming
LeetCode 120. 三角形最小路径和 每日一题
应用在温度检测仪中的温度传感芯片
射线与OBB相交检测
[PHP] PHP interface inheritance and interface multi inheritance principle and implementation method
Prometheus API deletes all data of a specified job