218. The Skyline Problem-Hard
一、题目描述

给定建筑的轮廓坐标,求叠加之后的轮廓结果
二、解法
这个题目最容易想到的思路是扫描法

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的更多相关文章
- [LeetCode#218] The Skyline Problem
Problem: A city's skyline is the outer contour of the silhouette formed by all the buildings in that ...
- [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 ...
- 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 ...
- 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 ...
- 218. The Skyline Problem
题目: A city's skyline is the outer contour of the silhouette formed by all the buildings in that city ...
- 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 ...
- 218. The Skyline Problem (LeetCode)
天际线问题,参考自: 百草园 天际线为当前线段的最高高度,所以用最大堆处理,当遍历到线段右端点时需要删除该线段的高度,priority_queue不提供删除的操作,要用unordered_map来标记 ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- [LeetCode] The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
- The Skyline Problem
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
随机推荐
- [CentOS]压缩+解压+打包命令大全
[CentOS]压缩+解压+打包命令大全 --------------- .tar 解包:tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注 ...
- RestfulApi 学习笔记——内容协商(三)
前言 什么是内容协商呢?是这样的,我们在请求的时候都有两个属性,一个是Content-Type,另一个是accept,这两个什么意思呢? content-type 这个是表示自己传输的是什么内容,就像 ...
- lattice烧录器回读功能。
经常被人问,lattice的 怎么回读,下面就说这个步骤. 烧录器检测到设备以后,以后选择operation,选择flash programming mode ,选择flash read and sa ...
- 试用阿里云GPU服务器进行深度学习模型训练
试用阿里云GPU服务器进行深度学习模型训练 最近在用PyTorch时发现在本地训练模型速度一言难尽,然后发现阿里云可以白嫖gpu服务器,只要没有申请过PAI-DSW资源的新老用户都可以申请5000CU ...
- State 和 Props的理解以及区别
一.state 一个组件的显示形态可以由数据状态和外部参数所决定,而数据状态就是state,一般在 constructor 中初始化 当需要修改里面的值的状态需要通过调用setState来改变,从而达 ...
- 对话 Dubbo 唤醒者北纬:3.0 将至,阿里核心电商业务也在用 Dubbo
简介: 如今,Dubbo 已经毕业一年,越来越多开发者开始询问 Dubbo 3.0 到底有哪些变化,阿里巴巴内部到底用不用 Dubbo,这是不是一个 KPI 开源项目以及 Dubbo 和 Spring ...
- [PHP] 如何让 php-fpm 的循环 echo 实时输出到浏览器
PHP 里开启实时输出方法是 ob_implicit_flush() , 但它大部分情况下都不管用, 因为 php.ini 配置里 output_buffering 输出缓冲大部分是 On 开启的 ...
- [FE] Quasar BEX 热加载区别: Chrome vs Firefox
Chrome 浏览器加载扩展程序时指定的是 src-bex 目录.Firefox 指定的是 manifest.json. Quasar 提供的热加载特性是 修改 src/ 目录里的文件,src-bex ...
- 从 Uno Platform 4 更新 Uno Platform 5 的迁移方法
本文记录我的一个小项目从 Uno Platform 4 更新 Uno Platform 5 的一些变更和迁移方法,由于项目太小,可能踩到的坑不多 官方文档: Migrating to Uno Plat ...
- OpenTK 入门 初始化窗口
本文属于 OpenTK 入门博客,这是一项使用 C# 做底层调用 OpenGL 和 OpenAL 和 OpenCL 的技术.但值得一提的是,如果是想做渲染相关的话,当前是不建议使用 OpenGL 的, ...