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. 【分库分表】sharding-jdbc—分片策略

    一.分片策略 Sharding-JDBC认为对于分片策略存有两种维度: 数据源分片策略(DatabaseShardingStrategy):数据被分配的目标数据源 表分片策略(TableShardin ...

  2. Openwrt架设GIT服务

    #下载宝刷LEDE版系统后, 在上面安装git包 opkg update opkg install git #安装好后在将git仓库装到SD(TF)卡上 #用fdisk对SD 卡分区 #fdisk / ...

  3. 前端学习之NaN浅析

    在学习Java集合的时候遇到了Float.isNaN(float)函数,点进去一看就不理解了,函数实现如下: public static boolean isNaN(float v) { return ...

  4. Visual Studio 2015 初体验

    据微软介绍每次发布的新版本,都承载着为开发者提供最高效的Visual Studio开发体验的使命.Visual Studio 2015亦延续了这一趋势,为开发者带来了进一步的生产力创新,包括调试和诊断 ...

  5. 20145302张薇《Java程序设计》第三周学习总结

    20145302张薇<Java程序设计>第三周学习总结 教材学习内容总结 第四章 定义类 一个原始码中有多少类就会有多少.class文档. 标准类 使用java.util.scanner让 ...

  6. 网络攻防工具介绍——Metasploit

    Metasploit 简介 Metasploit是一款开源的安全漏洞检测工具,可以帮助安全和IT专业人士识别安全性问题,验证漏洞的缓解措施,并管理专家驱动的安全性进行评估,提供真正的安全风险情报.这些 ...

  7. oracle update set select from 关联更新

    工作中有个需求,现在新表中有一些数据跟老表的基本一样,这样只需要把老表中数据搬到新表中就可以了,同时把不同的字段修改下数据即可,在修改字段时发现,需要指定一个条件,比如主键id,来修改某条记录,这样一 ...

  8. Hive-0.13安装

    Hive只需在使用节点安装即可. 1.上传tar包.解压   tar -zxvf apache-hive-0.13.0-bin.tar.gz -C /hadoop/  配置HIVE_HOME环境变量  ...

  9. jz2440使用openjtag+openocd+eclipse调试【学习笔记】

    平台:jz2440 作者:庄泽彬(欢迎转载,请注明作者) 说明:韦东山二期视频学习笔记 交叉编译工具:arm-linux-gcc (GCC) 3.4.5 eclipse版本:eclipse-cpp-l ...

  10. POJ - 3169 差分约束

    题意:n头牛,按照编号从左到右排列,两头牛可能在一起,接着有一些关系表示第a头牛与第b头牛相隔最多与最少的距离,最后求出第一头牛与最后一头牛的最大距离是多少,如         果最大距离无限大则输出 ...