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 ...
随机推荐
- flask通过线程池实现异步
from flask import Flask from time import sleep from concurrent.futures import ThreadPoolExecutor # D ...
- 《c#高级编程》第4章C#4.0中的更改(七)——命名参数和可选参数
一.概念 C#中的命名参数和可选参数是两种函数参数的特殊形式,它们可以提高代码的可读性和灵活性. 命名参数 命名参数允许我们在调用函数时指定参数名称,从而不必按照函数定义时的参数顺序进行传参.这样做可 ...
- 《c#高级编程》第3章C#3.0中的更改(五)——扩展方法
C#扩展方法是一种语法,可以为已有的类添加新的实例方法,而无需修改原来的类定义.它的语法形式为: ```csharppublic static void MyExtensionMethod(this ...
- Kubernetes 部署集群1.28.2版本(无坑)
初步搭建一个一个主节点和两个从节点Kubernetes 1.28.2 集群.先准备好机器 | host | hostname | os | role | hardware | | --- | --- ...
- 力扣438(Java)-找到字符串中所有字母异位词(中等)
题目: 给定两个字符串 s 和 p,找到 s 中所有 p 的 异位词 的子串,返回这些子串的起始索引.不考虑答案输出的顺序. 异位词 指由相同字母重排列形成的字符串(包括相同的字符串). 示例 1: ...
- 社区首款 OAM 可视化平台发布!
作者 | 徐运元,杭州谐云科技合伙人及资深架构师,云计算行业和 Kubernetes 生态资深从业者 导读:什么是 OAM?2019 年 10 月 17 日,阿里巴巴合伙人.阿里云智能基础产品事业部总 ...
- 龙蜥开源内核追踪利器 Surftrace:协议包解析效率提升 10 倍! | 龙蜥技术
简介:如何将网络报文与内核协议栈清晰关联起来精准追踪到关注的报文行进路径呢? 文/系统运维 SIG Surftrace 是由系统运维 SIG 推出的一个 ftrace 封装器和开发编译平台,让用 ...
- Serverless在游戏运营行业进行数据采集分析的最佳实践
简介: 这个架构不光适用于游戏运营行业,其实任何大数据采集传输的场景都是适用的,目前也已经有很多客户正在基于Serverless的架构跑在生产环境,或者正走在改造Serverless 架构的路上. 众 ...
- 解密 Dubbo 三大中心的部署架构
简介:Dubbo作为一个微服务框架,Dubbo SDK与应用服务绑定在同一个进程内,它跟随着应用服务被部署在分布式集群各个位置,为了在分布式环境下实现各个应用服务间的协作, Dubbo 定义了一些中 ...
- [FAQ] 英文字母输入时变成了胖体
如下,在输入法上右键,切换为 "半角" 即可. Link:https://www.cnblogs.com/farwish/p/17513598.html