Leetcode300. Longest Increasing Subsequence最长上升子序列
给定一个无序的整数数组,找到其中最长上升子序列的长度。
示例:
输入: [10,9,2,5,3,7,101,18] 输出: 4 解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4。
说明:
- 可能会有多种最长上升子序列的组合,你只需要输出对应的长度即可。
- 你算法的时间复杂度应该为 O(n2) 。
class Solution {
public:
int lengthOfLIS(vector<int>& nums)
{
int len = nums.size();
if (len == 0)
return 0;
vector<int> dp(len , 1);
for (int i = 0; i < len; i++)
{
for (int j = 0; j < i; j++)
{
if (nums[i] > nums[j])
{
dp[i] = max(dp[j] + 1, dp[i]);
}
}
}
int MAX = 1;
for (int i = 0; i < len; i++)
{
MAX = max(MAX, dp[i]);
}
return MAX;
}
};
Leetcode300. Longest Increasing Subsequence最长上升子序列的更多相关文章
- leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence
Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...
- [LintCode] Longest Increasing Subsequence 最长递增子序列
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...
- LeetCode 300. Longest Increasing Subsequence最长上升子序列 (C++/Java)
题目: Given an unsorted array of integers, find the length of longest increasing subsequence. Example: ...
- [LeetCode] Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- 673. Number of Longest Increasing Subsequence最长递增子序列的数量
[抄题]: Given an unsorted array of integers, find the number of longest increasing subsequence. Exampl ...
- [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. Example: Inp ...
- 300 Longest Increasing Subsequence 最长上升子序列
给出一个无序的整形数组,找到最长上升子序列的长度.例如,给出 [10, 9, 2, 5, 3, 7, 101, 18],最长的上升子序列是 [2, 3, 7, 101],因此它的长度是4.因为可能会有 ...
- poj 2533 Longest Ordered Subsequence 最长递增子序列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...
随机推荐
- C++相对路径和绝对路径
学习备忘 转自:http://www.cnblogs.com/vranger/p/3820783.html 电脑硬盘E盘下,建文件夹“test”,"test"下建立子文件夹“fil ...
- 异或前缀和——cf1186C
很思维的题,b的1个数和c的1个数相差为偶数时,必定有偶数个不同 反之必定有奇数个不同 #include <iostream> #include <cstdlib> #incl ...
- C/C++实现单向循环链表(尾指针,带头尾节点)
C语言实现单向循环链表,主要功能为空链表创建,链表初始化(头插法,尾插法),链表元素读取,按位置插入,(有序链表)按值插入,按位置删除,按值删除,清空链表,销毁链表. 单向循环链表和单向链表的区别:( ...
- 手机端判断安卓,iso,微信
var uaContains = function (key) { return navigator.userAgent.toLowerCase().indexOf(key.toLowerCase() ...
- IK分词器插件
(1)源码 https://github.com/medcl/elasticsearch-analysis-ik (2)releases https://github.com/medcl/elast ...
- java读取字符串,生成txt文件
/** * 读取字符串,生成txt 文件 已解决未设置编码时,在项目中直接打开文件,中文乱码问题 * WriteText.writeToText(musicInfo,fileName)直接调用 * * ...
- 08_springboot2.x自定义starter
概述 starter:启动器 1.这个场景需要使用到的依赖是什么? 2.如何编写自动配置 规则: @Configuration //指定这个类是一个配置类 @ConditionalOnXXX //在指 ...
- java_List接口
/** * java.util.list接口 extends Collection接口 * 1.有序的集合 * 2.有索引 * 3.元素可以重复 * * List中带索引的方法: *add:添加 * ...
- [JZOJ4648] 【NOIP2016提高A组模拟7.17】锦标赛
题目 描述 题目大意 有nnn个人,你要确定一个出场序列.每次新上台的人就会和擂主打一架,胜利的人继续当擂主.题目给出两两之间打架胜利(失败)的概率. 问111选手坚持到最后的最大概率. 思考历程 看 ...
- Django + Uwsgi + Nginx 的生产环境部署实战
目录 Django + Uwsgi + Nginx 的生产环境部署实战 安装Uwsgi 一.使用命令来启动django项目 二.使用配置文件来启动我们的Django项目 安装Nginx 配置Nginx ...