1. 思路:

假设柱子是
{ [0,1,4], [0,2,3], [3,5,3] }

每次扫描一条竖线后,对m进行竖线的压入或者弹出m中对应的左半边的操作,之后用cur表示处理完后当前所在的水平线,prev表示上一次天线点所在的水平线
prev初始化是0,这样碰到第一个柱子由于它高度大于0,一定会产生一个结果,prev = cur = 4

  1. class Solution {
  2. public:
  3. vector<pair<int, int>> getSkyline(vector<vector<int>>& buildings) {
  4. vector<pair<int, int> > h, res;
  5. multiset<int> m;
  6. int pre = , cur = ;
  7. for (auto &a : buildings) {
  8. h.push_back({a[], -a[]});
  9. h.push_back({a[], a[]});
  10. }
  11. sort(h.begin(), h.end());
  12. m.insert();
  13. for (auto &a : h) {
  14. if (a.second < ) m.insert(-a.second);
  15. else m.erase(m.find(a.second));
  16. cur = *prev(m.end());
  17. if (cur != pre) {
  18. res.push_back({a.first, cur});
  19. pre = cur;
  20. }
  21. }
  22. return res;
  23. }
  24. };

The Skyline Problem leetcode 详解的更多相关文章

  1. 由Leetcode详解算法 之 动态规划(DP)

    因为最近一段时间接触了一些Leetcode上的题目,发现许多题目的解题思路相似,从中其实可以了解某类算法的一些应用场景. 这个随笔系列就是我尝试的分析总结,希望也能给大家一些启发. 动态规划的基本概念 ...

  2. Leetcode 详解(ReverseWords)

    Leetcode里面关于字符串的一些问题,描述如下: Given an input string, reverse the string word by word. For example,Given ...

  3. Leetcode 详解(valid plindrome)

    Question: Given a string, determine if it is a palindrome, considering only alphanumeric characters ...

  4. Leetcode 详解(股票交易日)(动态规划DP)

    问题描述: 在股市的交易日中,假设最多可进行两次买卖(即买和卖的次数均小于等于2),规则是必须一笔成交后进行另一笔(即买-卖-买-卖的顺序进行).给出一天中的股票变化序列,请写一个程序计算一天可以获得 ...

  5. Leetcode详解Maximum Sum Subarray

    Question: Find the contiguous subarray within an array (containing at least one number) that has the ...

  6. Leetcode 详解(Substing without repeats character)

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  7. Leetcode 详解(Valid Number)

    Validate if a given string is numeric. Some examples:"0" => true" 0.1 " => ...

  8. Leetcode 详解(Implement strstr)

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  9. 218. The Skyline Problem (LeetCode)

    天际线问题,参考自: 百草园 天际线为当前线段的最高高度,所以用最大堆处理,当遍历到线段右端点时需要删除该线段的高度,priority_queue不提供删除的操作,要用unordered_map来标记 ...

随机推荐

  1. Wcf 文件上传下载

    wcf 文件上传的例子网上很多,我也是借鉴别人的示例.wcf 文件下载的示例网上就很少了,不知道是不是因为两者的处理方式比较类似,别人就没有再上传了.在此本人做下记录备忘. UploadFile.sv ...

  2. (转)Tomcat 配置成https协议

    Tomcat 配置成https协议 TomcatXMLServlet  在命令提示符窗口,进入Tomcat目录,执行以下命令: keytool -genkey -alias tomcat -keyal ...

  3. input type="file"去掉取消默认原来选择的文件

    很多时候我们上传文件点击取消后或我们制定了内容格式上传不符合,再次点击input="file"按钮时,选择的文件还是原来的文件,却又上传不.当时想在旁边多添加个按钮清除file里面 ...

  4. 版本问题 Java:Unsupported major.minor version 51.0 (unable to load class . . .

    导入别人的项目时报错  Java:Unsupported major.minor version 51.0 (unable to load class . . . 后发现错误是由于class编译器的J ...

  5. HTML一级导航制作

    今天分享一下简单导航栏的制作方法: 第一步:引入css样式表,新建一个id为nav的层,使用<ul>.<li>.<a>标签来制作完成效果. <!DOCTYPE ...

  6. Qt-剪切板

    ClipBoard 存在的意义 进程间数据共享. 方式 Drag And Drop: clipBoard的拖曳方式 app's ClipBoard 缺点 没有权限管理 在Model View中实现Dr ...

  7. SDN理解:目录

    为什么? 最近一直在学习SDN方面的知识,本着"最好的学习就是分享"的精神,记录下本系列的文章,尝试更好地去理解SDN这一正当红的技术. 如何? SDN领域现在已经充斥了大量的公司 ...

  8. JAVA上连接ubuntu14.04上的Hbase

    对于新手来说,连接虚拟机上的Hbase有点繁琐,而且网上的配置不太适合初学者,今天我就整理了一下,希望对你们有帮助,第一次发博客. 1.首先去官网下载Hbase的压缩包.我这里用的是1.2.1 htt ...

  9. nginx(2)

    上一篇: nginx(1) 负载均衡: linux集群的一种常见方式,即由多台服务器组成一个服务器集合实现某个特定需求,其中每台服务器都是等价的,从而实现负载均摊的目的. 反向代理: 是指以代理服务器 ...

  10. c/c++笔试面试经典函数实现

    /* strcpy函数实现 拷贝字符串 */ char* Strcpy(char* dst, char* src) { assert(dst != NULL && src != NUL ...