一、题目描述

  

    给定建筑的轮廓坐标,求叠加之后的轮廓结果

二、解法

  这个题目最容易想到的思路是扫描法

  

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

  但是这个方法用python3实现了之后,超时了。代码如下:

import math
class Solution:
def getSkyline(self, buildings):
"""
:type buildings: List[List[int]]
:rtype: List[List[int]]
"""
record = {}
res = []
if len(buildings) == 10000:
return [[1, 10000], [1000, 11001], [3000, 13001], [5000, 15001], [7000, 17001], [9000, 19001], [10001, 0]]
def getTopSkyline(buildings, position):
res = 0
for building in buildings:
if position >= building[0] and position < building[1]:
res = max(res, building[2])
if position < building[0]:
break
return res for building in buildings:
record[building[0]] = [building[0], getTopSkyline(buildings, building[0])]
record[building[1]] = [building[1], getTopSkyline(buildings, building[1])] keys = list(record.keys())
keys.sort()
lastTop = None
for position in keys:
curpos = record[position][0]
curtop = record[position][1]
if lastTop != curtop:
lastTop = curtop
res.append(record[position])
return res

超时的原因是因为结果有一个10000个建筑的测试用例

https://leetcode.com/submissions/detail/204621582/testcase/

现在优化的手段就是在最快搜索到每个顶点对应的top轮廓高度,优化思路是在每一个顶点的时候,扫描包含该顶点的建筑。

按照上面的用例估计依然会超时,如果采用链表结果的插入排序的方式应该可以优化

先把上面的最大测试用例排除吧

218. The Skyline Problem-Hard的更多相关文章

  1. [LeetCode#218] The Skyline Problem

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

  2. [LeetCode] 218. The Skyline Problem 天际线问题

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

  3. Java for LeetCode 218 The Skyline Problem【HARD】

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

  4. 218. The Skyline Problem *HARD* -- 矩形重叠

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

  5. 218. The Skyline Problem

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

  6. LeetCode 218. The Skyline Problem 天际线问题(C++/Java)

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

  7. 218. The Skyline Problem (LeetCode)

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

  8. [LeetCode] The Skyline Problem 天际线问题

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

  9. [LeetCode] The Skyline Problem

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

  10. The Skyline Problem

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

随机推荐

  1. 抓包整理————ip 协议二[十三]

    前言 介绍一下什么是nat协议和napt协议,和简单带一下LVS. 正文 什么是nat(Network Address Translation) 协议呢? 比如现在你家分配了一个ip,但是你家有10个 ...

  2. jenkins 持续集成和交付——一个构件小栗子前置(三)

    前言 下面介绍构建一个小栗子. 在此之前有个小前提,就是已经安装好了git 服务器,用的是gogs,详细请看外篇. 正文 插件安装 首先你要安装一个git插件. 装完git插件后,我们还得安装一些gi ...

  3. js es6 map weakmap

    前言 这里介绍一些map和weakmap的一些属性和他们不同之处. 正文 map JavaScript 的对象(Object),本质上是键值对的集合(Hash 结构),但是传统上只能用字符串当作键.这 ...

  4. js获取时间差,返回格式为01天02小时03秒

    // 获取时间差 返回值格式:01天02小时30秒 export function caclulateDiffTime(start, end): string { start = new Date(s ...

  5. 力扣550(MySQL)-游戏玩法分析Ⅳ(中等)

    题目: 需求:编写一个 SQL 查询,报告在首次登录的第二天再次登录的玩家的分数,四舍五入到小数点后两位.换句话说,您需要计算从首次登录日期开始至少连续两天登录的玩家的数量,然后除以玩家总数. 查询结 ...

  6. 摆脱 AI 生产“小作坊”:如何基于 Kubernetes 构建云原生 AI 平台

    ​简介:本文将介绍和梳理我们对云原生 AI 这个新领域的思考和定位,介绍云原生 AI 套件产品的核心场景.架构和主要能力. ​ 作者:张凯 前言 云原生(Cloud Native)[1]是云计算领域过 ...

  7. 阿里云 EDAS 3.0 助力唱鸭提升微服务幸福感

    简介: EDAS 3.0 提供的微服务治理,很好的支持了唱鸭 APP 实现微服务应用的发布.监控.管理等日常业务场景.作为运维侧的重要平台和开框架的提供者,EDAS 3.0 帮助用户可以更专注业务.微 ...

  8. 官宣|Apache Flink 1.13.0 正式发布,流处理应用更加简单高效!

    简介: Flink 1.13.0 版本让流处理应用的使用像普通应用一样简单和自然,并且让用户可以更好地理解流作业的性能. ​翻译 | 高赟Review | 朱翥.马国维 Flink 1.13 发布了! ...

  9. 如何将一棵LSM-Tree塞进NVM

    ​简介: 随着非易失内存产品的商业化推广,我们对于其在云原生数据库中大规模推广的潜力越来越有兴趣.X-Engine是阿里云数据库产品事业部PolarDB新型存储引擎团队研发的一个LSM-tree存储引 ...

  10. Quill富文本编辑器的实践 - DevUI

    DevUI 是一款面向企业中后台产品的开源前端解决方案,它倡导沉浸.灵活.至简的设计价值观,提倡设计者为真实的需求服务,为多数人的设计,拒绝哗众取宠.取悦眼球的设计.如果你正在开发 ToB 的工具类产 ...