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 ...
随机推荐
- Qt 从 QTransform 逆向解出 Translate/Scale/Rotate(平移/缩放/旋转)分析
QTransform 用于图形绘制,它定义了如何平移(translate).缩放(scale).切变(shear).旋转(rotate)或投射(project)坐标系.注意:QTransform 是作 ...
- Apache Flink 误用之痛
摘要:本文根据 Flink Forward 全球在线会议 · 中文精华版整理而成,围绕着项目的开始.需求分析.开发,以及测试.上线.运维整个生命周期展开,介绍了 Apache Flink 实践中的一些 ...
- Vineyard 加入 CNCF Sandbox,将继续瞄准云原生大数据分析领域
简介: Vineyard 是一个专为云原生环境下大数据分析场景中端到端工作流提供内存数据共享的分布式引擎,我们很高兴宣布 Vineyard 在 2021 年 4 月 27 日被云原生基金会(CNCF) ...
- 同程旅行基于 RocketMQ 高可用架构实践
简介: 我们在几年前决定引入 MQ 时,市场上已经有不少成熟的解决方案,比如 RabbitMQ , ActiveMQ,NSQ,Kafka 等.考虑到稳定性.维护成本.公司技术栈等因素,我们选择了 R ...
- 修复 GitLab 的 CI Runner 提示找不到 pwsh 执行文件
本文告诉大家如何修复使用 GitLab 的 Runner 做 CI 时提示 "pwsh": executable file not found in %PATH% 错误 有两个方法 ...
- webpack调优技巧
webpack优化主要有三个方面:1.提高构建速度,2.减少打包体积,3.优化用户体验 提高构建速度: 启用多线程 thread-loader 使用thread-loader插件可以启用多线程进行构建 ...
- vue项目hbuilder打包-微信登录调取手机微信登录权限
这个笔记得做好. 1.vue页面的点击事件 import {login,loginy,wxLog,wxLogin,logout} from '../network/login' wxloginBtn( ...
- 自动生成robot自动化测试用例
背景:java项目使用swagger管理接口,随着需求的开发接口也有增加,要从swagger界面中去查找出新增的接口是件很费时,效率很低的事情. 适用情况: java项目且适用swagger管理接口 ...
- 从SAP CRM上传设备到SAP ERP
文档<Step by step to download equipment from ERP with hierarchy>描述了从ERP复制设备到CRM的步骤.默认情况下,ERP中的设备 ...
- C#开发的CPU使用率小应用 - 开源研究系列文章 - 个人小作品
这次用C#编写一个CPU使用率的小应用.想了一下,大概需要两个内容:一个是获取CPU使用率:一个是托盘图标的动画效果.这两个内容在上次的博文中有介绍了,此博文为具体的应用的例子. 对于要实现的应用,首 ...