from heapq import *

 class Solution:
def getSkyline(self, LRH):
skyline = []
i, n = 0, len(LRH)
liveHR = []
while i < n or liveHR:
if not liveHR or i < n and LRH[i][0] <= -liveHR[0][1]:
x = LRH[i][0]
while i < n and LRH[i][0] == x:
heappush(liveHR, (-LRH[i][2], -LRH[i][1]))
i += 1
else:
x = -liveHR[0][1]
while liveHR and -liveHR[0][1] <= x:
heappop(liveHR)
height = len(liveHR) and -liveHR[0][0]
if not skyline or height != skyline[-1][1]:
skyline += [x, height],
return skyline

神题神解,

参考1:https://leetcode.com/problems/the-skyline-problem/discuss/61194/108-ms-17-lines-body-explained

参考2:https://briangordon.github.io/2014/08/the-skyline-problem.html

leetcode218的更多相关文章

  1. [Swift]LeetCode218. 天际线问题 | The Skyline Problem

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

  2. LeetCode218. The Skyline Problem

    https://leetcode.com/problems/the-skyline-problem/description/ A city's skyline is the outer contour ...

  3. leetcode218 天际线问题

    来自leetcode题解:扫描线法AlgsCG class Solution { public: vector<vector<int>> getSkyline(vector&l ...

  4. leetcode 日常清单

    a:excellent几乎一次ac或只有点小bug很快解决:半年后再重刷: b:经过艰难的debug和磕磕绊绊或者看了小提示才刷出来: c:经过艰难的debug没做出来,看答案刷的: 艾宾浩斯遗忘曲线 ...

随机推荐

  1. java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/JPEGCodec 解决方案

    使用java生成图片的时候,报了java.lang.NoClassDefFoundError: com/sun/image/codec/jpeg/JPEGCodec 错误. 根据这个类的api说明,在 ...

  2. 2、以自定义struct或struct指针作为map的Key

    若干问题: struct Node { int k, b; friend bool operator <(Node a, Node b) { return a.k < b.k; } }no ...

  3. Ubuntn16.04.3配置root权限及启用root用户

    景 如果你是测试环境需要在VM中装了Ubuntn,安装完成后会创建一个Ubuntn的默认用户,默认用户因为权限的问题很多系统的配置文件不可以打开,默认是只读状态. 那么可以通过以下两种方式切换到roo ...

  4. python3 urllib模块使用

    urllib模块使用 urllib.request urllib.request.urlopen(url, data=None, [timeout, ]*, cafile=None, capath=N ...

  5. appium+python自动化 adb shell按键操作

    前言 接着上篇介绍input里面的按键操作keyevent事件,发送手机上常用的一些按键操作 keyevent 1.keyevent事件有一张对应的表,可以直接发送对应的数字,也可以方式字符串,如下两 ...

  6. RPM包安装软件 -- 详细解读

    一.RPM包命名规则 1.RPM包在哪 RPM包在光盘中 2.RPM包命名原则 httpd-2.2.15-15.e16.centos.1.i686.rpm httpd 软件包名 2.2.15 软件版本 ...

  7. Flume原理解析【转】

    一.Flume简介 flume 作为 cloudera 开发的实时日志收集系统,受到了业界的认可与广泛应用.Flume 初始的发行版本目前被统称为 Flume OG(original generati ...

  8. linux中文件名有英文括号的问题

    文件名包含“()”的文件,输入“(“后按TAB键无法补全,手动输入文件全名也删除不了:提示bash: syntax error near unexpected token `('错误. 在linux中 ...

  9. C语言强化——链表(2)

    目录 链表的应用: 栈 循环队列 C语言实现动态数组 数组实现定长元素个数层次建树 队列实现不定元素个数层次建树 (*) 栈 栈(链表应用) "stack.h" #include ...

  10. [UE4]关卡蓝图