当前位置:网站首页>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;
}
}边栏推荐
- three. JS create cool snow effect
- 深度监听 数组深度监听 watch
- skimage学习(3)——Gamma 和 log对比度调整、直方图均衡、为灰度图像着色
- AutoLISP series (2): function function 2
- ByteDance Android gold, silver and four analysis, Android interview question app
- Horizontal and vertical centering method and compatibility
- 两类更新丢失及解决办法
- 字节跳动Android面试,知识点总结+面试题解析
- [Android -- data storage] use SQLite to store data
- 射线与OBB相交检测
猜你喜欢

如何快速检查钢网开口面积比是否符合 IPC7525

node:504报错

Spark Tuning (III): persistence reduces secondary queries

掌握这套精编Android高级面试题解析,oppoAndroid面试题

Lowcode: four ways to help transportation companies enhance supply chain management

谈谈 SAP 系统的权限管控和事务记录功能的实现

Pycharm terminal enables virtual environment

DNS 系列(一):为什么更新了 DNS 记录不生效?

Binary search tree (features)

Personal notes of graphics (2)
随机推荐
[PHP] PHP interface inheritance and interface multi inheritance principle and implementation method
应用在温度检测仪中的温度传感芯片
打造All-in-One应用开发平台,轻流树立无代码行业标杆
QT中自定义控件的创建到封装到工具栏过程(一):自定义控件的创建
深度监听 数组深度监听 watch
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
C语言进阶——函数指针
LeetCode 1186. 删除一次得到子数组最大和 每日一题
在哪个期货公司开期货户最安全?
Talk about the realization of authority control and transaction record function of SAP system
LocalStorage和SessionStorage
爬虫(17) - 面试(2) | 爬虫面试题库
二叉搜索树(基操篇)
Localstorage and sessionstorage
字节跳动Android金三银四解析,android面试题app
LeetCode 1043. 分隔数组以得到最大和 每日一题
谎牛计数(春季每日一题 53)
射线与OBB相交检测
DAPP defi NFT LP single and dual currency liquidity mining system development details and source code
[Android -- data storage] use SQLite to store data