当前位置:网站首页>27. Longest increasing subsequence
27. Longest increasing subsequence
2022-07-24 12:46:00 【Little happy】
300. The longest increasing subsequence
Give you an array of integers nums , Find the length of the longest strictly increasing subsequence .
Subsequences are sequences derived from arrays , 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
DP

class Solution {
public int lengthOfLIS(int[] nums) {
int n = nums.length;
int[] f = new int[n];
int res = 0;
f[0] = 1;
for(int i = 0;i<n;i++){
f[i] = 1;
for(int j = 0;j<i;j++){
if(nums[j]<nums[i]){
f[i]=Math.max(f[i],f[j]+1);
}
}
res = Math.max(res,f[i]);
}
return res;
}
}
Greedy Algorithm 、 Two points search
边栏推荐
- Node takes effect after using NVM to install under Windows system, but NPM does not take effect
- Leetcode-81. search rotation sort array II (binary search returns true/false)
- Okaleido tiger NFT即将登录Binance NFT平台
- Support liuhaiping
- 3.实现蛇和基本游戏界面
- How to mount NFS shares using autofs
- Cluster construction based on kubernetes v1.24.0 (II)
- Say no to blackmail virus, it's time to reshape data protection strategy
- 1.9. 触摸按钮(touch pad)测试
- 【C语言】详细的文件操作相关知识
猜你喜欢

基于Kubernetes v1.24.0的集群搭建(一)

高速成长的背后,华为云乌兰察布数据中心的绿色之道

No routines, no traps, no advertisements | are you sure you don't need this free instant messaging software?

Custom scroll bar

Implement is by yourself_ default_ constructible

SSM医院住院管理系统

6-16漏洞利用-rlogin最高权限登陆

How to realize the function of grabbing red envelopes in IM system?

Summary of recent interviews

Prototype inheritance
随机推荐
基于Kubernetes v1.24.0的集群搭建(一)
使用Jenkins搭建CI服务器
猿人学第五题
【C语言】详细的文件操作相关知识
sql的where+or的用法丢失条件
More functions and functions of the metauniverse lie in the deep transformation of the traditional way of life and production
基于matlab的声音识别
ERROR: [Synth 8-439] module ‘xxx‘ not found not found 错误解决办法
Taishan Office Technology Lecture: layout difficulties of paragraph borders
6-16漏洞利用-rlogin最高权限登陆
The setting float cannot float above the previous Div
有没有2、3w前期适合一个人干的创业项目呢?做自媒体可以吗?
Reserved instances & Savings Plans
Buckle practice - 24 remove repeated letters
Buckle practice - 27 score after turning the matrix
thinkphp 实现数据库备份
我在一个模块工程中使用注解配置了redis的序列化, 然后在另外一个模块引入这个模块,为什么这个配置
setAttribute、getAttribute、removeAttribute
What kind of experience is a monthly salary of 30000 yuan? Can we achieve this level as we media
nacos部署