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 ...
随机推荐
- TeamViewer 9发布-在Linux下安装运行
TeamViewer 9发布-在Linux下安装运行 来源:Linux中国 作者:未知 关注我们: 这篇指南介绍了怎么样在 RedHat. CentOS. Fedora 和 Debian. U ...
- 重新整理数据结构与算法(c#)——算法套马踏棋算法[三十三]
前言 马踏棋盘 概念在这,不做过多复述. https://baike.sogou.com/v58959803.htm?fromTitle=马踏棋盘 思路是这样子的,一匹马有上面几种做法,然后进行尝试, ...
- 实现JWT鉴权机制
一.是什么 JWT(JSON Web Token),本质就是一个字符串书写规范,如下图,作用是用来在用户和服务器之间传递安全可靠的信息 在目前前后端分离的开发过程中,使用token鉴权机制用于身份验证 ...
- AI极速批量换脸!Roop-unleashed下载介绍,可直播
要说AI换脸领域,最开始火的项目就是Roop了,Roop-unleashed作为Roop的嫡系分支,不仅继承了前者的强大基因,更是在功能上实现了重大突破与升级 核心特性 1.可以进行高精度的图片.视频 ...
- 《领域驱动设计》:从领域视角深入仓储(Repository)的设计和实现
简介: <领域驱动设计>中的Repository(下面将用仓储表示)层实际上是极具有挑战性的,对于它的理解,也十分重要.本文讲大部分内容都在众多前辈理论基础上,从一个崭新的领域视觉开始探索 ...
- 基于 Flink SQL 构建流批一体的 ETL 数据集成
简介: 如何利用 Flink SQL 构建流批一体的 ETL 数据集成. 本文整理自云邪.雪尽在 Flink Forward Asia 2020 的分享,该分享以 4 个章节来详细介绍如何利用 Fli ...
- 无缝融入 Kubernetes 生态 | 云原生网关支持 Ingress 资源
简介:Kubernetes 一贯的作风是通过定义标准来解决同一类问题,在解决集群对外流量管理的问题也不例外.Kubernetes 对集群入口点进行了进一步的统一抽象,提出了 3 种解决方案:Node ...
- [Ethereum] Gas Station Network (GSN) eip-1613 与 Gas Relay Network (GRN) eip-1077
在 Ethereum dapp 中,任何涉及状态改动的交易都需要消耗 Gas,这限制了很多没有钱包或者 ETH 的用户对 dapp 的采用. 理念 让非以太用户能够访问智能合约 (如dapps),允许 ...
- dotnet C# 推荐一个适合新手入门阅读学习的控制台游戏项目
对于 C# 编程新手,学习语法和框架是必要的,但是如何将它们灵活地运用到实际项目中,是一个更高层次的挑战.如果只是死记硬背语法规则和框架用法,而没有足够的编程实践,很难提高编程水平和逻辑思维.这个时候 ...
- EFK+logstash构建日志收集平台
一.环境 k8s集群: 控制节点:192.168.199.131 主机名:master 配置:4核6G 工作节点:192.168.199.128 主机名:monitor 配置:4核4G 1.1 ...