当前位置:网站首页>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
边栏推荐
- leetcode第 302 场周赛复盘
- How to realize the function of grabbing red envelopes in IM system?
- Teach you how to use power Bi to realize four kinds of visual charts
- C language course design -- hotel management system
- Is there any entrepreneurship project suitable for one person in the early stage of 2W and 3W? Is it OK to be we media?
- I used annotations to configure the serialization of redis in one module project, and then introduced this module in another module. Why is this configuration
- 中国消费者和产业链都很难离开苹果,iPhone的影响力太大了
- The setting float cannot float above the previous Div
- Implement is by yourself_ default_ constructible
- Support liuhaiping
猜你喜欢

The price of domestic flagship mobile phones is nearly 6000, but they can't even beat iphone12. It's clear who users choose
![Error: [synth 8-439] module 'xxx' not found not found error solution](/img/47/bb03cc26e254332bf815c80bafb243.png)
Error: [synth 8-439] module 'xxx' not found not found error solution

How to realize the function of grabbing red envelopes in IM system?
如何用WebGPU流畅渲染百万级2D物体?

Cluster construction based on kubernetes v1.24.0 (III)

Everything about native crash
Say no to blackmail virus, it's time to reshape data protection strategy

突破内存墙能带来什么?看火山引擎智能推荐服务节支增效实战

Reserved instances & Savings Plans

SSM在线校园相册管理平台
随机推荐
Solutions to problems in IE6 browser
The seventh topic of ape Anthropology
Cluster construction based on kubernetes v1.24.0 (II)
Nacos deployment
[C language] detailed knowledge of document operation
It is difficult for Chinese consumers and industrial chains to leave apple, and iPhone has too much influence
3.实现蛇和基本游戏界面
国产旗舰手机定价近六千,却连iPhone12都打不过,用户选谁很明确
Get the current month and year and the previous 11 months
Everything about native crash
SSM在线租房售房平台多城市版本
[leetcode]- linked list-3
I used annotations to configure the serialization of redis in one module project, and then introduced this module in another module. Why is this configuration
Buckle exercise - 32 divided into k equal subsets
Taishan Office Technology Lecture: layout difficulties of paragraph borders
Is there a free and commercially available website for US media video clips?
Basic SQL server operation problems - only when lists are used and identity_ Only when insert is on can the display value be set for the identification column in the table
让一套代码完美适配各种屏幕
Buckle practice - 25 non overlapping intervals
C language course design -- hotel management system