第一次做题思路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. CYPHER 语句(Neo4j)

    CYPHER 语句(Neo4j) 创建电影关系图 新增 查找 修改 删除 导入 格式转换 创建电影关系图 CREATE (TheMatrix:Movie {title:'The Matrix', re ...

  2. i春秋2020新春公益赛WP

    Re Factory 主函数fork了一个子进程,父进程添加了一个信号处理器用于比对input,然后死循环挂起.子进程读入input,然后调用了关键函数. 跟进关键函数,发现是从一段内存中读取数据,然 ...

  3. 扫描转换算法——DDA、中点画线画圆、椭圆

    我的理解:在光栅图形学中,由于每一个点的表示都只能是整数值,所以光栅图形学实际只是对对实际图形的近似表示. 数值微分法(DDA):以下PPT截图来自北京化工大学李辉老师 代码实现: import ma ...

  4. 详解Cisco ACS AAA认证-1(转)

    转自:http://www.360doc.com/content/12/0611/17/8797027_217495523.shtml作者:luobo2012 近来,有些同学会问到关于AAA认证的问题 ...

  5. NOIp2017TG解题报告

    NOIp2018RP++! 虽然没去但还得写写QAQ D1T1 : 小凯的疑惑 数学题 手推几组数据然后发现规律 \(Ans = (a-1)(b-1)+1\) AC in 1minite D1T2 : ...

  6. 多标签图像分类任务的评价方法-mAP

    http://blog.sina.com.cn/s/blog_9db078090102whzw.html 多标签图像分类(Multi-label Image Classification)任务中图片的 ...

  7. 微信小程序生成海报保存图片到相册小测试

    test.wxml <canvas style="width:{{imageWidth}}px;height:{{imageHeight}}px;" canvas-id=&q ...

  8. PyTorch基础——使用卷积神经网络识别手写数字

    一.介绍 实验内容 内容包括用 PyTorch 来实现一个卷积神经网络,从而实现手写数字识别任务. 除此之外,还对卷积神经网络的卷积核.特征图等进行了分析,引出了过滤器的概念,并简单示了卷积神经网络的 ...

  9. React 通过注释自动生成文档

    最近找了一些文档的生成工具,结果发现了这个 React Styleguidist 可以通过注释,自动生成对应的文档,对于 react 库来说十分方便 安装 npm i -D react-stylegu ...

  10. Cell theory|Bulk RNA-seq|Cellar heterogeneity|Micromanipulation|Limiting dilution|LCM|FACS|MACS|Droplet|10X genomics|Human cell atlas|Spatially resolved transcriptomes|ST|Slide-seq|SeqFISH|MERFISH

    生物信息学 Cell theory:7个要点 All known living things are made up of one or more cells. All living cells ar ...