[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: ...
随机推荐
- SEO初步学习之新站优化
新站优化技巧:新站有两个月扶持期,在扶持期间仅做一件事,提交大量优质受众的原创,且内容为不间断,即每天定点定量发布文章,使得蜘蛛对网站形成爬行习惯,新站初期内容为王,优化为辅. 虽说优化为辅,却不可或 ...
- l1 和l2范数的真实意义
很长时间一直没有明白真实的含义,十一期间补充一下这方面的知识. l0 范数是 ||x||0 = xi (xi不等于0)代表非0数字的个数,[1,2,3,4,5] 非0个数为5,[0,1,2,0,3] ...
- ssh登录脚本
#!/usr/bin/expect set timeout 100 set passwd "your password" spawn shell expect "key& ...
- Sublime Text3 作Markdown编辑器 配置
准备 Sublime 配置 1 Package Control 2 安装插件 测试 其他 1. 准备 Windows操作系统 Sublime Text3 编辑器 Web浏览器 2. Sublime 配 ...
- JavaEE--分布式对象
参考:http://blog.csdn.net/smcwwh/article/details/7080997 1.客户与服务器的角色 所有分布式编程技术的基本思想都很简单:客户计算机产生一个请求,然后 ...
- BBS数据库设计
BBS数据库设计 一.BBS数据库设计 # models.py from django.db import models # Create your models here. from django. ...
- \_\_init\_\_和\_\_new\_\_
__init__和__new__ 一.__new__和__init__ 曾经我幼稚的以为认识了python的__init__()方法就相当于认识了类构造器,结果,__new__()方法突然出现在我眼前 ...
- ansible puppet saltstack三款自动化运维工具的对比
一.基础介绍 ansible基础介绍可参考:http://www.linuxidc.com/Linux/2017-12/149671.htm puppet基础介绍可参考:http://www.linu ...
- 《Premiere Pro 2020》初心版_v3 14.0.1.71
<Premiere Pro 2020>初心版_v3 下载地址(78e7) SHA1:8B081196C1756CE9477A0D056D6331907B3DDFDC 版本信息 发行版 ...
- linux 中的.so和.a文件
Linux下的.so是基于Linux下的动态链接,其功能和作用类似与windows下.dll文件. 下面是关于.so的介绍: 一.引言 通常情况下,对函数库的链接是放在编译时期(compile tim ...