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. 【jdk】使用wget下载jdk8

    因为在oracle官网下载jdk需要 如果直接在linux中使用 wget命令下载,实际下载是一个html文件,所以需要通过一下命令 wget --no-check-certificate --no- ...

  2. STL进阶--成员函数 vs 算法

    容器的成员函数 vs 算法 容器中同名的函数 List: void remove(const T); template<class Comp> void remove_if(Comp); ...

  3. centos 7 免密登录

    本文转载自:https://www.cnblogs.com/hobinly/p/6039844.html 环境示例 Centos7  192.168.1.101 master Centos7 192. ...

  4. gulp学习总结

    一.gulp使用-博客推荐: http://www.sheyilin.com/2016/02/gulp_introduce/ 二.gulp的作用 gulp是一个前端构建工具,它是一个工具框架,可以通过 ...

  5. selectedIndex 属性

    selectedIndex 属性可设置或返回下拉列表中被选选项的索引号. 注释:若允许多重选择,则仅会返回第一个被选选项的索引号. 语法 selectObject.selectedIndex=numb ...

  6. ROS-MikroTik-RouterOS-培训认证各种证书

    官方原文: https://mikrotik.com/training/about MikroTik certified training programs MTCNA - MikroTik Cert ...

  7. Java中的局部变量、成员变量和静态变量

    直接看代码 public class Variable { // 静态变量,属于类的变量,且用关键字static声明,不属于实例,虽然可以通过实例来调用,但是不建议 private static in ...

  8. library之目录

    组件之fragment: Android viewpager结合fragment的相关优化: 组件之webview: WebView的使用及实战(cookie同步和cookie清除); Android ...

  9. Mysql 5.7 系列命令 timestamp类型的字段不能设默认值为“0000-00-00 00:00:00” 要设为`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新',

    一.show相关命令语句 1.查看表的索引 show index from tbl_name; 1 table:表名 non_unique:索引是非唯一的?.0否,唯一是索引的.1是,是非唯一索引.( ...

  10. typescript泛型类 泛型方法

    /* 泛型:软件工程中,我们不仅要创建一致的定义良好的API,同时也要考虑可重用性. 组件不仅能够支持当前的数据类型,同时也能支持未来的数据类型,这在创建大型系统时为你提供了十分灵活的功能. 在像C# ...