当前位置:网站首页>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;
}
}边栏推荐
猜你喜欢

node:504报错

Advanced C language -- function pointer

The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit

AutoLISP series (3): function function 3

最新Android面试合集,android视频提取音频

Tragedy caused by deleting the console statement
![[medical segmentation] attention Unet](/img/f4/cf5b8fe543a19a5554897a09b26e68.png)
[medical segmentation] attention Unet

"The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."
字节跳动Android金三银四解析,android面试题app
直接上干货,100%好评
随机推荐
【医学分割】attention-unet
node:504报错
Three. JS series (2): API structure diagram-2
The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit
Laravel service provider instance tutorial - create a service provider test instance
数据中台落地实施之法
LeetCode 1031. 两个非重叠子数组的最大和 每日一题
[Android -- data storage] use SQLite to store data
Deep listening array deep listening watch
The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
Find tags in prefab in unity editing mode
The differences between exit, exit (0), exit (1), exit ('0 '), exit ('1'), die and return in PHP
SqlServer2014+: 创建表的同时创建索引
Introduction and use of gateway
What is the difference between IP address and physical address
LeetCode 1774. 最接近目标价格的甜点成本 每日一题
Laravel constructor and middleware execution order
Pisa-Proxy SQL 解析之 Lex & Yacc
掌握这套精编Android高级面试题解析,oppoAndroid面试题
偶然升职的内心独白