思路:

假设柱子是
{ [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. 不再害羞,过程比结果更重要;分享一套 CodeSmit 代码生成模板。

    住博客园 5 年了,以前也发过一些博文,但都在 一天后 / 几周后 / 几年后 将它删了:因为感觉代码写得不好:不清晰或侵入太大,哪怕只有一句侵入. 可是最近重写一套 CodeSmith 代码生成模板 ...

  2. SharePoint 2013/2010 中的日历重合 (Calendars Overlay)

    本文介绍 SharePoint 2013/2010 中的日历重合 (Calendars Overlay). 日历重合 (Calendars Overlay)的用途就是将 不多于10个日历或日历视图聚集 ...

  3. 【C++自我精讲】基础系列四 static

    [C++自我精讲]基础系列四 static 0 前言 变量的存储类型:存储类型按变量的生存期划分,分动态存储方式和静态存储方式. 1)动态存储方式的变量,生存期为变量所在的作用域.即程序运行到此变量时 ...

  4. Android开发之Ubuntu上Eclipse不显示手机设备

    一.准备工作   A.开启Android设备,用USB数据线连接到Ubuntu系统.   B.启用设备的USB调试模试    C.启动Eclipse,在Devices栏会现一个有很多???号的不明设备 ...

  5. 009-程序集路径Web窗体

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs& ...

  6. 用js使得输入框input只能输入数字

        JS判断只能是数字和小数点1.文本框只能输入数字代码(小数点也不能输入)<input onkeyup="this.value=this.value.replace(/\D/g, ...

  7. 深入分析:微信小程序与H5的区别

    作为前端工程师,从前端的视角,为大家分析下微信小程序和HTML5与之间的主要区别 第一条是运行环境的不同. 传统的HTML5的运行环境是浏览器,包括webview,而微信小程序的运行环境并非完整的浏览 ...

  8. Maven之(四)Maven命令

    常用命令 从某种意义上来说,软件是帮助不懂程序的人来操作计算机的,图形化界面尤其如此.在上个世纪,比尔盖茨之所以成为世界首富,微软之所以IT界的巨鳄,就是因为Windows开图形化操作之先河,并抢先占 ...

  9. HDU 1728 逃离迷宫(DFS||BFS)

    逃离迷宫 Problem Description 给定一个m × n (m行, n列)的迷宫,迷宫中有两个位置,gloria想从迷宫的一个位置走到另外一个位置,当然迷宫中有些地方是空地,gloria可 ...

  10. Fedora24 升级到25

    1 安装dnf-plugin-system-upgrade dnf install dnf-plugin-system-upgrade 2 更新软件包 dnf system-upgrade downl ...