当前位置:网站首页>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
- Horizontal and vertical centering method and compatibility
- 爬虫(17) - 面试(2) | 爬虫面试题库
- 最新阿里P7技术体系,妈妈再也不用担心我找工作了
- 《产品经理必读:五种经典的创新思维模型》的读后感
- 水平垂直居中 方法 和兼容
- Opencv personal notes
- Prometheus API deletes all data of a specified job
- LeetCode 1155. 掷骰子的N种方法 每日一题
- 作为Android开发程序员,android高级面试
猜你喜欢
随机推荐
null == undefined
在哪个期货公司开期货户最安全?
【DesignMode】模板方法模式(Template method pattern)
QT视频传输
"The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."
掌握这套精编Android高级面试题解析,oppoAndroid面试题
值得一看,面试考点与面试技巧
skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
LeetCode 1049. 最后一块石头的重量 II 每日一题
Laravel5.1 Routing - routing packets
全网“追杀”钟薛高
最新高频Android面试题目分享,带你一起探究Android事件分发机制
Personal notes of graphics (1)
模拟Servlet的本质
字节跳动Android面试,知识点总结+面试题解析
Three. JS series (2): API structure diagram-2
Read PG in data warehouse in one article_ stat
[medical segmentation] attention Unet
【Seaborn】组合图表:PairPlot和JointPlot
应用在温度检测仪中的温度传感芯片