当前位置:网站首页>LeetCode 300. 最长递增子序列 每日一题
LeetCode 300. 最长递增子序列 每日一题
2022-07-07 15:32:00 【@小红花】
问题描述
给你一个整数数组 nums ,找到其中最长严格递增子序列的长度。
子序列 是由数组派生而来的序列,删除(或不删除)数组中的元素而不改变其余元素的顺序。例如,[3,6,2,7] 是数组 [0,3,1,6,2,2,7] 的子序列。
示例 1:输入:nums = [10,9,2,5,3,7,101,18]
输出:4
解释:最长递增子序列是 [2,3,7,101],因此长度为 4 。
示例 2:输入:nums = [0,1,0,3,2,3]
输出:4
示例 3:输入:nums = [7,7,7,7,7,7,7]
输出:1
提示:
1 <= nums.length <= 2500
-104 <= nums[i] <= 104来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/longest-increasing-subsequence
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
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;
}
}边栏推荐
- Horizontal and vertical centering method and compatibility
- PHP has its own filtering and escape functions
- LocalStorage和SessionStorage
- How can laravel get the public path
- Balanced binary tree (AVL)
- 低代码(lowcode)帮助运输公司增强供应链管理的4种方式
- [designmode] template method pattern
- dapp丨defi丨nft丨lp单双币流动性挖矿系统开发详细说明及源码
- Pycharm terminal enables virtual environment
- 无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
猜你喜欢
随机推荐
The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
Deep listening array deep listening watch
字节跳动Android面试,知识点总结+面试题解析
Record the migration process of a project
C语言进阶——函数指针
Opportunity interview experience summary
LocalStorage和SessionStorage
Module VI
OpenGL personal notes
The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit
1亿单身男女“在线相亲”,撑起130亿IPO
Pisa-Proxy SQL 解析之 Lex & Yacc
【DesignMode】模板方法模式(Template method pattern)
第九届 蓝桥杯 决赛 交换次数
null == undefined
Personal notes of graphics (2)
【医学分割】attention-unet
记录Servlet学习时的一次乱码
Spark Tuning (III): persistence reduces secondary queries
谎牛计数(春季每日一题 53)
![[designmode] facade patterns](/img/79/cde2c18e2ec8b08697662ac352ff90.png)






