思路:

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

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

class Solution {
public:
vector<pair<int, int>> getSkyline(vector<vector<int>>& buildings) {
vector<pair<int, int> > h, res;
multiset<int> m;
int pre = , cur = ;
for (auto &a : buildings) {
h.push_back({a[], -a[]});
h.push_back({a[], a[]});
}
sort(h.begin(), h.end());
m.insert();
for (auto &a : h) {
if (a.second < ) m.insert(-a.second);
else m.erase(m.find(a.second));
cur = *prev(m.end());
if (cur != pre) {
res.push_back({a.first, cur});
pre = cur;
}
}
return res;
}
};

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. 挖一下插件v1.5版本发布

    Chrome图片下载插件,支持网页截屏 v.1.5更新说明: 1.增加下载图片按日期分类保存选项,便于管理,用户可根据需要开启/关闭此设置 2.增加网页图片采集快捷键: (1)采集页面图片(Ctrl+ ...

  2. ADO读取EXCEL

    窗体上拖放ADOQuery1,DataSetProvider1,DataSource1,ClientDataSet1,OpenDialog1, ExcelApplication1,ExcelWorkb ...

  3. ADS的go to命令

    我们有时候在一个函数右键没有看到“go to”选项,这是因为没有Make,要先Make之后才能使用go to 命令

  4. [置顶] vs2008 编译adb 支持4.2 android 系统(改进版)

    QQ: 2506314894 本想晚些时候放出来的,但是按捺不住啊,所以修改了之后就立即放出来了.先说明一下,这次用的adb 的源码比较新的,用的vs2008 编译出来,只有一个exe 文件,直接就可 ...

  5. 命令版本git 分支篇-----不断更新中

    最近应用开发的过程中出现了一个小问题,顺便记录一下原因和方法--命令版本 开发中想看看过去某个版本的代码,我们先查看log git log commit f224a720b8192165a4e70f2 ...

  6. “System.FormatException”类型的异常在 mscorlib.dll 中发生,但未在用户代码中进行处理 其他信息: 该字符串未被识别为有效的 DateTime。

    前台用过jquery ajax将值传递到 后台的一般处理程序 并且报了这个异常 原因是:前台传递过来的时间格式不对  需要把 "/"换成 "-"   例如:20 ...

  7. virtualbox 中的linux 共享文件

    首先要安装VirtualBox的增强版功能(VBoxGuestAdditions) 在 设备--->安装增强版功能----->运行,重启电脑. 出现这个问题,看看安装增强功能的时候,有没有 ...

  8. 【.NET】字符串处理类库

    类名:DealString,方法清单列好在头上. /// 1.截取字符串,最后加3个小数点 /// 2.获得指定Url的参数的string类型值 /// 3.判断数据类型 /// 4.过滤JS标记 / ...

  9. Ch2 空间配置器(allocator) ---笔记

    2.1 空间配置器的标准接口 allocator的必要接口: allocator::value_type allocator::pointer allocator::const_pointer all ...

  10. 常用的HTTP方法

    方法                 描述 是否包含主体 GET  从服务器获得一份文档 否 HEAD  只从服务器获得响应报文的首部 否 POST  向服务器发送需要处理的数据 是 PUT  将请求 ...