[LC] 300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.
Example:
Input:[10,9,2,5,3,7,101,18]Output: 4
Explanation: The longest increasing subsequence is[2,3,7,101], therefore the length is4.
Note:
- There may be more than one LIS combination, it is only necessary for you to return the length.
- Your algorithm should run in O(n2) complexity.
Follow up: Could you improve it to O(n log n) time complexity?
class Solution {
public int lengthOfLIS(int[] nums) {
if (nums == null || nums.length == 0) {
return 0;
}
int[] arr = new int[nums.length];
int res = 0;
for (int i = 0; i < nums.length; i++) {
arr[i] = 1;
for (int j = 0; j < i; j++) {
if (nums[j] < nums[i]) {
// note which one + 1
arr[i] = Math.max(arr[i], arr[j] + 1);
}
}
res = Math.max(res, arr[i]);
}
return res;
}
}
[LC] 300. Longest Increasing Subsequence的更多相关文章
- 300. Longest Increasing Subsequence
题目: Given an unsorted array of integers, find the length of longest increasing subsequence. For exam ...
- [LeetCode] 300. Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...
- Leetcode 300 Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- leetcode@ [300] Longest Increasing Subsequence (记忆化搜索)
https://leetcode.com/problems/longest-increasing-subsequence/ Given an unsorted array of integers, f ...
- [leetcode]300. Longest Increasing Subsequence最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...
- 【leetcode】300.Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- 300. Longest Increasing Subsequence(LIS最长递增子序列 动态规划)
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- [leetcode] 300. Longest Increasing Subsequence (Medium)
题意: 求最长增长的子序列的长度. 思路: 利用DP存取以i作为最大点的子序列长度. Runtime: 20 ms, faster than 35.21% of C++ online submissi ...
- LeetCode 300. Longest Increasing Subsequence最长上升子序列 (C++/Java)
题目: Given an unsorted array of integers, find the length of longest increasing subsequence. Example: ...
随机推荐
- Idea Spring工程不识别注解
如图所示 Idea工具报出很多注解不识别,开始怀疑是 工具问题,重装Idea.配置lombak都不行,切换分支发现正常,一定是合入代码修改啥了,一行行比对,果然是这行 import org.sprin ...
- Linux安装已编译好的FFmpeg,基于centos7
1.访问https://johnvansickle.com/ffmpeg/ 2.下载地址:https://johnvansickle.com/ffmpeg/releases/ffmpeg-releas ...
- 18 11 04 初用单片机 c语言学习
---恢复内容开始--- 1 作为单片机使用的的 c 语言学习 ++ 增位运算符 在原有基础上加一 -- 相同 由于单片机只有 ~ 取反 & 两个 参数里有没有 | 两个 参数里有没有 ^ 两 ...
- SALESGROSSSALES_成本_利润
//获取成本GETCOST_TMP:NoConcatenateLOAD T_SAL_OUTSTOCK.LE_ID, [T_SAL_OUTSTOCK.LCY CODE], T_SAL_OUTSTOCK. ...
- 深入理解JVM - 垃圾收集器
垃圾回收主要是要解决3件事情: 那些内存需要回收? 如何回收? 什么时候回收? 那些内存需要回收 在强引用的情况下已经“死”了的对象就需要回收,在非强引用的情况下视情况回收.在java里面,几乎所有的 ...
- 吴裕雄--天生自然TensorFlow2教程:numpy [ ] 索引
import tensorflow as tf a = tf.ones([1, 5, 5, 3]) a.shape a[0][0] numpy : 索引 a = tf.random.normal([4 ...
- 吴裕雄--天生自然 JAVA开发学习:Number & Math 类
int a = 5000; float b = 13.65f; byte c = 0x4a; public class Test{ public static void main(String arg ...
- 第4章 ZK基本特性与基于Linux的ZK客户端命令行学习
第4章 ZK基本特性与基于Linux的ZK客户端命令行学习 4-1 zookeeper常用命令行操作 4-2 session的基本原理与create命令的使用
- 【转载】解决Cannot download "https://github.com/sass/node-sass/releases/download...问题
因很早做了一个小demo,并且在其他成熟的电脑上(node配置好的)下载依赖包没什么问题,最近就在新的电脑上配置好所有东西后,去下载这个demo的依赖包,就出现了node-sass无法正常解析的问题, ...
- pytorch(ch5
读取图片数据集::# -*- coding: utf-8 -*-import torch as tfrom torch.utils import dataimport osfrom PIL impor ...