Given an unsorted array of integers, find the length of longest increasing subsequence.

For example,
Given [10, 9, 2, 5, 3, 7, 101, 18],
The longest increasing subsequence is [2, 3, 7, 101], therefore the length is 4. Note that 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?

dp解决,注意这里的递增序列不是指连续的递增 ,可以是不连续的, 代码如下:

 class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
if(nums.size() <= ) return nums.size();
vector<int> dp(nums.size(), );
int maxVal = ;
for(int i = ; i < nums.size(); ++i){
dp[i] = ;
for(int j = ; j < i; ++j){
if(nums[j] < nums[i]){
dp[i] = max(dp[i], dp[j]+);
maxVal = max(dp[i], maxVal);
}
}
}
return maxVal;
}
};

LeetCode OJ:Longest Increasing Subsequence(最长递增序列)的更多相关文章

  1. [LeetCode] Number of Longest Increasing Subsequence 最长递增序列的个数

    Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...

  2. [LeetCode] 300. Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...

  3. [LeetCode] 673. Number of Longest Increasing Subsequence 最长递增序列的个数

    Given an unsorted array of integers, find the number of longest increasing subsequence. Example 1: I ...

  4. [leetcode]300. Longest Increasing Subsequence最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Inp ...

  5. leetcode300. Longest Increasing Subsequence 最长递增子序列 、674. Longest Continuous Increasing Subsequence

    Longest Increasing Subsequence 最长递增子序列 子序列不是数组中连续的数. dp表达的意思是以i结尾的最长子序列,而不是前i个数字的最长子序列. 初始化是dp所有的都为1 ...

  6. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  7. [LintCode] Longest Increasing Subsequence 最长递增子序列

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

  8. 673. Number of Longest Increasing Subsequence最长递增子序列的数量

    [抄题]: Given an unsorted array of integers, find the number of longest increasing subsequence. Exampl ...

  9. LeetCode 300. Longest Increasing Subsequence最长上升子序列 (C++/Java)

    题目: Given an unsorted array of integers, find the length of longest increasing subsequence. Example: ...

  10. POJ 2533 Longest Ordered Subsequence 最长递增序列

      Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...

随机推荐

  1. 50条常用liunx命令整理

    1.pwd命令 :确定自己在那个目录 使用方法:在liunx命令输入框里面输入pwd,自动就会显示出自己现在在那个目录下 操作截图: 此时正处在root目录里面 2.cd命令:切换目录的意思 使用方法 ...

  2. playbook管理配置文件

    前言:在生产环境中,经常需要更改多台机器配置文件,所以用playbook来实现nginx配置文件的管理 一.更新nginx配置文件并重新加载 1. 创建对应目录结构 mkdir -p /etc/ans ...

  3. 屏蔽信号的多路选择I/O

    前边提到了多路I/O的方法,这一章屏蔽信号的多路选择与之前的多路I/O一致,只是增加了屏蔽信号的作用.多路选择I/O中我们使用的是select函数,屏蔽信号的多路选择I/O使用的是pselect函数, ...

  4. lamp编译详解

    首先确认系统环境:centos6.4 min版本 1.安装需要的开发环境 yum groupinstall "Development Tools" "Server Pla ...

  5. 20145314郑凯杰《信息安全系统设计基础》第5周学习总结 part B

    20145314郑凯杰<信息安全系统设计基础>第5周学习总结 part B 在前四天的学习中,我主要对课本知识进行了总结,在本周后三天的学习过程中,我进行实践并截图. http://www ...

  6. linux目录结构及文件权限

    安装banner用到的指令: 第一步: sudo apt-get update 第二步: sudo apt-get install sysvbanner 成功了 创建新用户指令: sudo addus ...

  7. 20145231熊梓宏《网络对抗》逆向及Bof基础

    20145231网络对抗<逆向及Bof基础> 实验目的与要求 1.本次实践的对象是一个名为pwn1的linux可执行文件. 2.若该程序正常执行,则main函数会调用foo函数,foo函数 ...

  8. Flask-最简单的Python http服务框架使用

    环境准备 Python + pip + Flask sudo easy_install pip sudo pip install flask 代码如下(做了个jieba分词的服务) # encodin ...

  9. 2017 beijing icpc E - Rikka with Competition

    2017-09-22 22:01:19 writer:pprp As we know, Rikka is poor at math. Yuta is worrying about this situa ...

  10. STL list用法总结

    2017-08-20 15:17:30 writer:pprp list是一种线性复杂度的容器,很快 /* name : usage of List writer : pprp declare : n ...