[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: ...
随机推荐
- 洛谷 P1379 八数码难题(map && 双向bfs)
题目传送门 解题思路: 一道bfs,本题最难的一点就是如何储存已经被访问过的状态,如果直接开一个bool数组,空间肯定会炸,所以我们要用另一个数据结构存,STL大法好,用map来存,直接AC. AC代 ...
- [Python]h5py/__init__.py:36:
个人博客地址:https://www.bearoom.xyz/2019/08/24/python-devolop-env-hdf5-problem/ 安装tensorflow之后,在导入tensorf ...
- 如何解决Tomcat端口号被占用
在eclipse中配置好tomcat服务器后,启动时提示错误如下图 提示端口被占用. 第一种方法: 结束占用端口的进程 第一步:netstat -aon|findstr "端口号" ...
- excel 导出长数据 变成科学计数 解决办法
加 “\t”
- 开启新项目时启动tomcat的一个小问题
Application context 这里为啥只有是空的,才能正常启动tomcat?
- 吴裕雄--天生自然 JAVA开发学习:方法
/** 返回两个整型变量数据的较大值 */ public static int max(int num1, int num2) { int result; if (num1 > num2) re ...
- c# 之循环 ,while 和do---while还有for
㈠while循环 循环条件 是个bool值,为true时执行循环,为false退出循环.break一般不单独的使用,而是跟着if判断一起使用,表示,当满足某些条件的时候,就退出循环了. 循环体 一般总 ...
- python编程:从入门到实践----第六章:字典>练习
6-1 人:使用一个字典来存储一个熟人的信息,包括名.姓.年龄和居住的城市.该字典应包含键first_name .last_name .age 和city .将存储在该字典中的每项信息都打印出来. f ...
- unity学习 5.x解包
using System.Collections;using System.Collections.Generic;using UnityEngine; public class bundleload ...
- Tomcat8 启动报错
Tomcat8启动报错: java.lang.NoSuchMethodError:javax.servlet.ServletContext.getClassLoader 在网上搜索后,发现此类问题大都 ...