当前位置:网站首页>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;
}
}边栏推荐
猜你喜欢

Master this promotion path and share interview materials

值得一看,面试考点与面试技巧

《产品经理必读:五种经典的创新思维模型》的读后感

水平垂直居中 方法 和兼容

Binary search tree (basic operation)

QT 图片背景色像素处理法
As an Android Developer programmer, Android advanced interview

The team of East China Normal University proposed the systematic molecular implementation of convolutional neural network with DNA regulation circuit
![[vulnhub range] thales:1](/img/fb/721d08697afe9b26c94fede628c4d1.png)
[vulnhub range] thales:1

C语言进阶——函数指针
随机推荐
skimage学习(2)——RGB转灰度、RGB 转 HSV、直方图匹配
LeetCode 152. 乘积最大子数组 每日一题
二叉搜索树(基操篇)
LeetCode 213. 打家劫舍 II 每日一题
LeetCode 1477. 找两个和为目标值且不重叠的子数组 每日一题
正在准备面试,分享面经
整理几个重要的Android知识,高级Android开发面试题
Process from creation to encapsulation of custom controls in QT to toolbar (I): creation of custom controls
DNS 系列(一):为什么更新了 DNS 记录不生效?
PHP realizes wechat applet face recognition and face brushing login function
[medical segmentation] attention Unet
Three. JS series (3): porting shaders in shadertoy
null == undefined
《产品经理必读:五种经典的创新思维模型》的读后感
Pycharm terminal enables virtual environment
LeetCode 312. 戳气球 每日一题
记录Servlet学习时的一次乱码
Spark Tuning (III): persistence reduces secondary queries
[vulnhub range] thales:1
LeetCode 120. 三角形最小路径和 每日一题