[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: ...
随机推荐
- Python—二叉树数据结构
二叉树 简介: 二叉树是每个结点最多有两个子树的树结构.通常子树被称作“左子树”(left subtree)和“右子树”(right subtree). 二叉树二叉树的链式存储: 将二叉树的节点定义为 ...
- Detected both log4j-over-slf4j.jar AND bound slf4j-log4j12.jar on the class path 解决过程
原因:log4j-over-slf4j和slf4j-log4j12是跟Java日志系统相关的两个jar包,如果同时出现,就可能会引起堆栈异常 解决:找到依赖冲突发生位置,排除一个即可. 问题是 如何找 ...
- MySQL--Centos7下安装5.7.19
https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html https://segmentfault.com/a/11900000 ...
- PAT Advanced 1051 Pop Sequence (25) [栈模拟]
题目 Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, -, N and ...
- UML-类图-需要写关联名称吗?
概念模型:需要写关联名称:类图:不需要写关联名称. 注意,概念模型关联线不需要箭头.
- luffy项目:基于vue与drf前后台分离项目(1)
""" 1.业务逻辑:登录注册 - 主页(基础信息展示) - 课程页(复杂信息展示)- 课程订单生产与支付 - 上线订单生成 2.实际项目开发的技术点: git版本控制 ...
- idea快捷键(最常用)
--跳到上一空白行 ctrl+alt+enter --跳到下一空白行 shift+enter --为代码生成包裹快(try catch等) ctrl+alt+t --跳到某行 ctrl+g --实现父 ...
- Spring Test+JUnit4整合使用测试ZZJ_淘淘商城项目:day01(RESTful Web Service)
针对整合的Dao层与Service层,在做spring与通用Mapper和分页插件相关测试时比较麻烦.如果只用JUnit测试,需要每次Test方法里初始化一下applicationContext,效率 ...
- K 破忒头的匿名信(ac自动机+小dp)
题:https://ac.nowcoder.com/acm/contest/4010/K 题意:用一些模式串凑成一个目标串,每个模式串有消耗,问组合的最小消耗,或不能组成输出-1: 分析:典型的AC自 ...
- rsync配置文件模板
用脚本实现服务端rsyncd的部署cat /server/scripts/rsync_install.sh #!/bin/bash #安装包 yum install -y rsync &> ...