当前位置:网站首页>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;
}
}边栏推荐
- 编程模式-表驱动编程
- ATM system
- The latest interview experience of Android manufacturers in 2022, Android view+handler+binder
- Personal notes of graphics (4)
- LeetCode 1049. 最后一块石头的重量 II 每日一题
- [summary of knowledge] summary of notes on using SVN in PHP
- DNS 系列(一):为什么更新了 DNS 记录不生效?
- logback. XML configure logs of different levels and set color output
- time标准库
- 正在准备面试,分享面经
猜你喜欢

爬虫(17) - 面试(2) | 爬虫面试题库

Master this set of refined Android advanced interview questions analysis, oppoandroid interview questions

《产品经理必读:五种经典的创新思维模型》的读后感

Lowcode: four ways to help transportation companies enhance supply chain management
正在准备面试,分享面经

最新阿里P7技术体系,妈妈再也不用担心我找工作了

【DesignMode】外观模式 (facade patterns)

记录Servlet学习时的一次乱码

字节跳动高工面试,轻松入门flutter
Direct dry goods, 100% praise
随机推荐
LeetCode 312. 戳气球 每日一题
Lowcode: four ways to help transportation companies enhance supply chain management
ATM系统
skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
【C 语言】 题集 of Ⅹ
Personal notes of graphics (4)
Sort out several important Android knowledge and advanced Android development interview questions
Vs2019 configuration matrix library eigen
skimage学习(1)
LeetCode 213. 打家劫舍 II 每日一题
浅浅理解.net core的路由
[designmode] facade patterns
Three. JS series (2): API structure diagram-2
Personal notes of graphics (2)
LeetCode 1774. 最接近目标价格的甜点成本 每日一题
[medical segmentation] attention Unet
01tire+ chain forward star +dfs+ greedy exercise one
作为Android开发程序员,android高级面试
Advanced C language -- function pointer
全网“追杀”钟薛高