当前位置:网站首页>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;
}
}
边栏推荐
- spark调优(三):持久化减少二次查询
- 预售17.9万,恒驰5能不能火?产品力在线,就看怎么卖
- LeetCode 1155. 掷骰子的N种方法 每日一题
- Opportunity interview experience summary
- The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit
- 爬虫(17) - 面试(2) | 爬虫面试题库
- 整理几个重要的Android知识,高级Android开发面试题
- node:504报错
- Prometheus API deletes all data of a specified job
- 编程模式-表驱动编程
猜你喜欢
Lowcode: four ways to help transportation companies enhance supply chain management
全网“追杀”钟薛高
面向接口编程
Temperature sensor chip used in temperature detector
Direct dry goods, 100% praise
使用JSON.stringify()去实现深拷贝,要小心哦,可能有巨坑
掌握这个提升路径,面试资料分享
Spark Tuning (III): persistence reduces secondary queries
[designmode] proxy pattern
字节跳动Android面试,知识点总结+面试题解析
随机推荐
Sort out several important Android knowledge and advanced Android development interview questions
Personal notes of graphics (4)
最新Android面试合集,android视频提取音频
LeetCode 403. 青蛙过河 每日一题
运算符
Three. JS series (1): API structure diagram-1
Imitate the choice of enterprise wechat conference room
LeetCode 1774. 最接近目标价格的甜点成本 每日一题
skimage学习(3)——使灰度滤镜适应 RGB 图像、免疫组化染色分离颜色、过滤区域最大值
LeetCode 1696. 跳跃游戏 VI 每日一题
Arduino 控制的双足机器人
《产品经理必读:五种经典的创新思维模型》的读后感
Opportunity interview experience summary
Laravel changed the session from file saving to database saving
记录Servlet学习时的一次乱码
LocalStorage和SessionStorage
QT 图片背景色像素处理法
DAPP defi NFT LP single and dual currency liquidity mining system development details and source code
【DesignMode】模板方法模式(Template method pattern)
spark调优(三):持久化减少二次查询