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 ...
随机推荐
- soj114 中位数
题意:给你一个长度为2n-1的数组A,设Bi是A的1~2i-1的中位数.问打乱A,有多少种不同的B序列? 标程: #include<bits/stdc++.h> using namespa ...
- thinkphp 模板注释
模板支持注释功能,该注释文字在最终页面不会显示,仅供模板制作人员参考和识别. 大理石平台厂家 单行注释 格式: {/* 注释内容 */ } 或 {// 注释内容 } 例如: {// 这是模板注释内容 ...
- vue+Iview+gulp 生成文档说明
1.安装npm gulp相关插件 比如:gulp.gulp-concat.gulp-htmlmin.gulp-cssmin.gulp-cheerio.gulp-clean 2. 编写gulpfile. ...
- 修改sql server表字段的字符串
网站标题被注入黑链接,使用sql脚本update修改字段内的字符串截取UPDATE [qds0460132_db].[dbo].[Blood_News] SET [Blood_Name] = SU ...
- Django之13种必会查询
1.常见的13中查询方式(必须记住) <1> all(): 查询所有结果 <2> filter(**kwargs): 它包含了与所给筛选条件相匹配的对象 <3> g ...
- 使用CEfSharp之旅(2) js前台事件执行后台方法
原文:使用CEfSharp之旅(2) js前台事件执行后台方法 版权声明:本文为博主原创文章,未经博主允许不得转载.可点击关注博主 ,不明白的进群191065815 我的群里问 https://blo ...
- LeetCode 206.反转链表(Python3)
题目: 反转一个单链表. 示例: 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1->NULL 进阶:你可 ...
- Android开发 TextView的开发记录
前言 此篇博客是记录一些TextView开发上一些少用的开发功能项.目前开发记录如下: 添加图片 文字滚动 添加省略号 实现长文的收起和展开功能 改变一个字符串里自定字符的颜色或者大小 效果字体(粗体 ...
- Android 开发 MediaRecorder音频录制
前言 MediaRecorder类是Android sdk提供的一个专门用于音视频录制,一般利用手机麦克风采集音频和摄像头采集图像.这个类是属于简单的音频录制类,录制音频简单容易但是对音频流的控制也比 ...
- No packages marked for update
问题:用yum安装docker,更新yum存储时,报以下错误,导致yum坏了 [root@localhost yum.repos.d]# vi docker.repo [root@localhost ...