当前位置:网站首页>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
边栏推荐
- Vscode solves the problem of terminal Chinese garbled code
- 突破内存墙能带来什么?看火山引擎智能推荐服务节支增效实战
- 生信识图 之 点图基础
- Zabbix5.0.8-odbc monitoring Oracle11g
- 自己实现is_default_constructible
- 深圳地铁12号线第二批工程验收通过 预计7月28日试运行
- 3.实现蛇和基本游戏界面
- Okaleido tiger NFT is about to log in to binance NFT platform
- Behind the rapid growth, Huawei cloud Wulanchabu data center is the green way
- Efficientformer: lightweight vit backbone
猜你喜欢

支持刘海屏
EfficientFormer:轻量化ViT Backbone

【功能测试】项目的测试——登录和发布文章功能

C language course design -- hotel management system

从零实现深度学习框架——再探多层双向RNN的实现

Seckill implementation diagram

Implement is by yourself_ default_ constructible

Zabbix5.0.8-odbc monitoring Oracle11g

Get the current month and year and the previous 11 months

微信小程序生成二维码
随机推荐
使用TypeFace设置TextView的文字字体
Mobilevit: challenge the end-to-side overlord of mobilenet
class
SSM在线校园相册管理平台
树莓派自建 NAS 云盘之——数据自动备份
突破内存墙能带来什么?看火山引擎智能推荐服务节支增效实战
Taishan Office Technology Lecture: layout difficulties of paragraph borders
Buckle practice - 31 effective tic tac toe games
Native Crash的一切
支持刘海屏
Reserved instances & Savings Plans
Raspberry pie self built NAS cloud disk -- raspberry pie built network storage disk
Is it safe to open an account on Oriental Fortune online? Is there a threshold for opening an account?
1.9. 触摸按钮(touch pad)测试
如何使用autofs挂载NFS共享
猿人学第六题
SSM在线考试系统含文档
Say no to blackmail virus, it's time to reshape data protection strategy
leetcode第 302 场周赛复盘
Buckle practice - 24 remove repeated letters