第一次做题思路201511092250

1.采用map存储,key为nums[i],value为以nums[i]为结尾的最大递增子序列的长度

2.采用map里面的lower_bounder函数直接找出第一个大于或等于nums[i]的位置,位置ite--,然后遍历前面的数,找出比nums[i]的数里面,长度len最长的,令nums[i]的最大递增子序列的长度为len+1

3.AC时间为148ms

class Solution {
public:
int lengthOfLIS(vector<int>& nums) {
map<int, int> m;
int maxLength = 0;
for (int i = 0; i < nums.size(); i++)
{
map<int, int>::iterator ite = m.lower_bound(nums[i]);
if (ite == m.begin())
m[nums[i]] = 1;
else
{
ite--;
int tmpMax = ite->second + 1;
for (; ite != m.begin(); ite--)//寻找比nums[i]小的数,并在这些数里面,找出长度最大的
tmpMax = max(tmpMax, ite->second + 1);
if (ite == m.begin())//寻找比nums[i]小的数,并在这些数里面,找出长度最大的
tmpMax = max(tmpMax, ite->second + 1);
m[nums[i]] = tmpMax;
}
maxLength = max(maxLength, m[nums[i]]);
}
return maxLength;
}
};

Longest Increasing Subsequence (Medium)的更多相关文章

  1. [leetcode] 300. Longest Increasing Subsequence (Medium)

    题意: 求最长增长的子序列的长度. 思路: 利用DP存取以i作为最大点的子序列长度. Runtime: 20 ms, faster than 35.21% of C++ online submissi ...

  2. 【leetcode】300.Longest Increasing Subsequence

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

  3. 65.Longest Increasing Subsequence(最长增长子序列)

    Level:   Medium 题目描述: Given an unsorted array of integers, find the length of longest increasing sub ...

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

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

  5. [tem]Longest Increasing Subsequence(LIS)

    Longest Increasing Subsequence(LIS) 一个美丽的名字 非常经典的线性结构dp [朴素]:O(n^2) d(i)=max{0,d(j) :j<i&& ...

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

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

  7. Leetcode 300 Longest Increasing Subsequence

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

  8. [LeetCode] Longest Increasing Subsequence

    Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest incre ...

  9. The Longest Increasing Subsequence (LIS)

    传送门 The task is to find the length of the longest subsequence in a given array of integers such that ...

随机推荐

  1. Java之创建线程的方式三:实现Callable接口

    import java.util.concurrent.Callable;import java.util.concurrent.ExecutionException;import java.util ...

  2. 洛谷 P1060开心的金明

    题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间他自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NN元钱就行”.今 ...

  3. C#压缩解压zip 文件

    /// <summary> /// Zip 压缩文件 /// </summary> public class Zip { public Zip() { } #region 加压 ...

  4. java线程——notifyAll通知的泄露

    版权声明:本文为CSDN博主「兰亭风雨」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明.原文链接:https://blog.csdn.net/ns_code/ar ...

  5. liunx 常用操作(自用)

    Centos7解压文件 tar -zxvf 文件名[test.tar.gz] Centos7安装vim yum -y install vim* Centos7安装ifconfig yum instal ...

  6. Problem for Nazar CodeForces - 1151C (前缀和)

    Problem for Nazar Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for ...

  7. PAT甲级——1146 Topological Order (25分)

    This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topol ...

  8. py02_02:pyc的解释

    1. Python是一门解释型语言吗? 我初学Python时,听到的关于Python的第一句话就是,Python是一门解释性语言,我就这样一直相信下去,直到发现了*.pyc文件的存在.如果是解释型语言 ...

  9. C++随机迷宫生成[转载]

    原文:http://tieba.baidu.com/p/2596809144 #include<iostream.h> #include"time.h" #includ ...

  10. Tooltips2

    #include<windows.h> #include<Commctrl.h> #include"resource.h" #pragma comment( ...