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

Interface oriented programming

1亿单身男女“在线相亲”,撑起130亿IPO

运算符

"The" "PIP" "entry cannot be recognized as the name of a cmdlet, function, script file, or runnable program."

【医学分割】attention-unet

网关Gateway的介绍与使用

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

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

Have fun | latest progress of "spacecraft program" activities

Master this set of refined Android advanced interview questions analysis, oppoandroid interview questions
随机推荐
[designmode] flyweight pattern
three. JS create cool snow effect
LeetCode-SQL第一天
Laravel changed the session from file saving to database saving
Interface oriented programming
QT 图片背景色像素处理法
Read PG in data warehouse in one article_ stat
整理几个重要的Android知识,高级Android开发面试题
The difference and working principle between compiler and interpreter
Direct dry goods, 100% praise
URL和URI的关系
Master this promotion path and share interview materials
LeetCode 1654. 到家的最少跳跃次数 每日一题
DNS 系列(一):为什么更新了 DNS 记录不生效?
值得一看,面试考点与面试技巧
如何快速检查钢网开口面积比是否符合 IPC7525
【MySql进阶】索引详解(一):索引数据页结构
Pisa-Proxy SQL 解析之 Lex & Yacc
二叉搜索树(基操篇)
谈谈 SAP 系统的权限管控和事务记录功能的实现