当前位置:网站首页>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;
}
}
边栏推荐
猜你喜欢
谈谈 SAP 系统的权限管控和事务记录功能的实现
Personal notes of graphics (3)
最新高频Android面试题目分享,带你一起探究Android事件分发机制
Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
QT中自定义控件的创建到封装到工具栏过程(二):自定义控件封装到工具栏
Skimage learning (3) -- gamma and log contrast adjustment, histogram equalization, coloring gray images
As an Android Developer programmer, Android advanced interview
整理几个重要的Android知识,高级Android开发面试题
直接上干货,100%好评
[medical segmentation] attention Unet
随机推荐
LeetCode 1626. 无矛盾的最佳球队 每日一题
【图像传感器】相关双采样CDS
LeetCode 1986. 完成任务的最少工作时间段 每日一题
As an Android Developer programmer, Android advanced interview
面向接口编程
Imitate the choice of enterprise wechat conference room
谎牛计数(春季每日一题 53)
【C 语言】 题集 of Ⅹ
Three. JS series (3): porting shaders in shadertoy
正在准备面试,分享面经
Sort out several important Android knowledge and advanced Android development interview questions
AutoLISP series (2): function function 2
Geoserver2.18 series (5): connect to SQLSERVER database
[designmode] proxy pattern
值得一看,面试考点与面试技巧
【DesignMode】代理模式(proxy pattern)
【MySql进阶】索引详解(一):索引数据页结构
Horizontal and vertical centering method and compatibility
浅浅理解.net core的路由
23. 合并K个升序链表-c语言