当前位置:网站首页>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;
}
}
边栏推荐
- 无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
- DAPP defi NFT LP single and dual currency liquidity mining system development details and source code
- 【PHP】PHP接口继承及接口多继承原理与实现方法
- 低代码(lowcode)帮助运输公司增强供应链管理的4种方式
- 整理几个重要的Android知识,高级Android开发面试题
- Opencv personal notes
- Personal notes of graphics (3)
- Laravel constructor and middleware execution order
- URL和URI的关系
- Sort out several important Android knowledge and advanced Android development interview questions
猜你喜欢
最新Android高级面试题汇总,Android面试题及答案
无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
Advanced C language -- function pointer
网关Gateway的介绍与使用
预测——灰色预测
Tragedy caused by deleting the console statement
Pycharm terminal enables virtual environment
Interface oriented programming
【DesignMode】外观模式 (facade patterns)
Temperature sensor chip used in temperature detector
随机推荐
Opencv configuration 2019vs
Binary search tree (features)
深度监听 数组深度监听 watch
Prediction - Grey Prediction
SqlServer2014+: 创建表的同时创建索引
【DesignMode】外观模式 (facade patterns)
Module VI
Record the migration process of a project
无法将“pip”项识别为 cmdlet、函数、脚本文件或可运行程序的名称
Personal notes of graphics (4)
华东师大团队提出,具有DNA调控电路的卷积神经网络的系统分子实现
ATM系统
LeetCode 152. 乘积最大子数组 每日一题
Binary search tree (basic operation)
LeetCode 1696. 跳跃游戏 VI 每日一题
[vulnhub range] thales:1
Laravel post shows an exception when submitting data
[designmode] flyweight pattern
Personal notes of graphics (3)
Laravel service provider instance tutorial - create a service provider test instance