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. JSON.stringify without quotes on properties?

    https://stackoverflow.com/questions/11233498/json-stringify-without-quotes-on-properties/11233515 va ...

  2. Web安全学习笔记之Nmap脚本编写

    0x00 Nmap脚本简介 夜无眠,看了一下Nmap官方的英文API文档(全是English),瞬间心态崩塌,不想吐槽它们的nmap官网前端太丑了=.=,但是都是大牛啊,挺敬佩开源开发者的. Nmap ...

  3. Python3.x:selenium获取iframe内嵌页面的源码

    Python3.x:selenium获取iframe内嵌页面的源码 前言 在一些网页中经常会看到ifrmae/frame标签,iframe是嵌入式框架一般用来在已有的页面中嵌入另一个页面,当一个元素在 ...

  4. 20145216史婧瑶《Java程序设计》第2周学习总结

    20145216 <Java程序设计>第2周学习总结 教材学习内容总结 第三章 基础语法 3.1 类型.变量与运算符 •类型 •基本类型 •整数:short(占2字节).int(占4字节) ...

  5. 20145310《Java程序设计》第4次实验报告

    20145310<Java程序设计>第4次实验报告 实验内容 搭建Android环境 运行Android 修改代码并输出自己的学号 实验步骤 搭建Android环境 安装Android S ...

  6. java问卷调查

    你对自己的未来有什么规划?做了哪些准备? 我对自己今后五年有一定的规划,那就是多学一些信息技术上的知识,当今的社会高度信息化,且在以后也有高速发展的势头,所以我认为只有学习足够的专业知识,才可以适应未 ...

  7. Remote System Explorer Operation总是运行后台服务,卡死eclipse

    阿里云 > 教程中心 > android教程 > Remote System Explorer Operation总是运行后台服务,卡死eclipse Remote System E ...

  8. 定制Writable类

    以IntWritable为例介绍,定制writable的步骤 //继承 WritableComparable接口(继承了writable接口和comparable接口) public class In ...

  9. Jenkins 安装教程

    第一部分,安装Jenkins 1.首先在Jenkins repo yum源和Key [root@jenkins ~]# wget http://pkg.jenkins.io/redhat-stable ...

  10. PHP中的strtotime()函数

    参见: http://www.phppan.com/2011/06/php-strtotime/ http://developer.51cto.com/art/201107/275478.htm PH ...