21.1.28 LeetCode 218.The Skyline Problem

LeetCode218. The Skyline Problem分治法 题意:轮廓问题,不好描述。首先怎么分: 不停对半分 停止条件1:为空时,直接返回空 停止条件2:大小为1时,直接返回左上角点和右下角点。 那么怎么合并? 维护两个变量:l,r l为左半部分当前位置,r为右半部分当前位置 维护两个变量:h1,h2 h1表示左半部分当前位置高度,h2表示右半部分档期位置高度 如果当前位置左半部分横坐标更小,就更新h1,从左半部分选元素; 如果当前位置右半部分横坐标更小, 阅读详情

218. The Skyline Problem

题意

一座城市的天际线是从远处看时,该城市所有建筑物形成的轮廓的外部轮廓。给定所有建筑的位置和高度,返回这些建筑共同形成的天际线。
每个建筑物的几何信息在阵列建筑物中给出
其中建筑物[i]=[lefti,righti,heighti]:
lefti是第i个建筑左边缘的x坐标。
righti是第i个建筑右边缘的x坐标。
heighti是第i栋楼的高度。

你可以假设所有的建筑都是完美的长方形,坐落在高度为0的绝对平坦的表面上。

天际线应表示为按x坐标排序的“关键点”列表,形式为[[x1,y1],[x2,y2],…]。
每个关键点都是天际线中某个水平线段的左端点,但列表中的最后一点除外,该点始终具有y坐标0,用于标记天际线的终点,即最右边的建筑的终点。最左边和最右边建筑之间的任何地面都应该是天际线轮廓的一部分。
注意:输出天际线中不能有高度相等的连续水平线。例如,[…,[2 3],[4 5],[7 5],[11 5],[12 7],…]是不可接受的;高度5的三行应在最终输出中合并为一行,例如:[…,[2 3],[4 5],[12 7],…]

Input: buildings = [[2,9,10],[3,7,15],[5,12,12],[15,20,10],[19,24,8]]
Output: [[2,10],[3,15],[7,12],[12,0],[15,10],[20,8],[24,0]]
Explanation:
Figure A shows the buildings of the input.
Figure B shows the skyline formed by those buildings. The red points in f

igure B represent the key points in the output list.

思路

思路来源链接

代码

Java实现

import java.util.*;
class Solution
{
    public List<List<Integer>> getSkyline(int[][] buildings)
    {
        List<List<Integer>> answer = new ArrayList<>();

        List<int[]> buildLines = new ArrayList<>();//天际线

        for (int[] points : buildings)
        {
            //拆分
            // build[0, 1, 2]
            // build[left, right, height]
            buildLines.add(new int[] { points[0], -points[2] });
            buildLines.add(new int[] { points[1], points[2] });
        }


        // 从左往右再从小到大排序
        // buildLines[0, 1]
        // buildLines[bound, height]
        buildLines.sort((a, b) -> a[0] != b[0] ? a[0] - b[0] : a[1] - b[1]);
        //创建最大堆
        var maxHeap = new PriorityQueue<Integer>((a, b) -> b - a);

        maxHeap.add(0);
        int Highest = 0;//当前堆中最大高度

         //遍历buildlines数组
        for (int[] points : buildLines)
        {
            if (points[1] < 0)
            {
                maxHeap.add(-points[1]);
            }
            else
            {
                maxHeap.remove(points[1]);
            }
            //当前最大高度
            int nowHeight=0;
            nowHeight = maxHeap.peek();
            //加入轮廓点
            if (nowHeight != Highest)
            {
                answer.add(Arrays.asList(points[0], nowHeight));
                Highest = nowHeight;
            }
        }
        return answer;
    }
}
深入解析Xilinx IDELAYE2在FPGA时序优化中的关键作用与实战配置 本文深入解析了Xilinx FPGA中IDELAYE2模块在时序优化中的关键作用。作为精密的信号延时微调器,IDELAYE2通过可编程的抽头延迟,有效解决高速接口中数据与时钟的相位偏差问题。文章详细阐述了其必须与IDELAYCTRL配对使用的核心机制,并对比分析了FIXED、VARIABLE和VAR_LOAD三种工作模式的实战配置方法与代码示例,为FPGA工程师提供了解决时序收敛难题的关键硬件配置指南。 阅读详情

相关推荐

openEuler在虚拟机的网络配置

ethernet0.virtualDev 可以配置成其他类型的虚拟网络适配器。常见的选项包括:vlance - 用于模拟 AMD PCnet32 LANCE 网络适配器,支持10Mbps。e1000 - 用于模拟 Intel E1000 千兆网络适配器,支持1Gbps。e1000e - 用于模拟更现代的 Intel E1000e 千兆网络适配器。vmxnet - 用于 VMware 的自定义网络适配器,性能更好但需要安装 VMware Tools。

FHY1221的博客 2941

Leetcode 218. The Skyline Problem 线段树

A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as

无名山丘,崛起成峰 2647

Android逆向分析

Android 逆向开发是指对已发布的 Android 应用进行分析和破解,以了解应用程序的内部工作原理,获取应用程序的敏感信息,或者修改应用程序的行为。Android应用 Java编写的,利用Android SDK编译代码,并并且把所有的数据和资源文件打包成一个APK(Android Package)文件这是一个后缀名为.apk的压缩文件,apk文件中包含了一个Anddroid应用程序的所有内容,是Android平台用于安装应用程序的文件。

qq_51598534的博客 6312

leetcode 218: The Skyline Problem

leetcode 218: The Skyline Problem java python c++

西施豆腐渣 5858

Veritas NetBackup 10.1 Windows安装指南:从账户配置到完整部署

本文详细介绍了Veritas NetBackup 10.1在Windows系统上的完整安装流程,从账户配置到部署验证。重点讲解了创建专用服务账户、安装组件选择、许可证输入等关键步骤,并提供了常见问题排查和进阶配置建议,帮助用户顺利完成企业级备份解决方案的部署。

weixin_26765287的博客 458

TDSQL分布式数据库架构深度解析:从核心组件到高可用实践

分布式数据库是应对海量数据与高并发写入的关键技术,其核心价值在于通过水平扩展突破单机瓶颈,同时保持数据一致性与系统可用性。TDSQL作为一款兼容MySQL协议的分布式数据库产品,由调度、计算、存储与元数据四大核心组件构成,通过分片键路由将数据均匀分布至多节点,并借助强同步复制与两阶段提交协议分别保障零数据丢失与跨节点事务原子性。在金融、政务等对一致性要求严苛的场景下,TDSQL提供的主备自动切换、在线扩容及同城容灾能力,使其成为核心业务系统的可靠底座。本文从整体设计思路出发,结合实际部署与运维视角,详解分片

weixin_30846347的博客 302

[LeetCode 218] The Skyline Problem

A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings a

coder 进阶的专栏 1710

深度强化学习:Actor-Critic、A2C、A3C

Actor-Critic算法是强化学习中常用的一种方法,policy-based,通过演员和评论员或者是策略网络和价值网络的结合进行学习

weixin_51995147的博客 1433

[leetcode] 218. The Skyline Problem 解题报告

题目链接: https://leetcode.com/problems/the-skyline-problem/ A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose

小榕流光的专栏 6635

Android13 SurfaceFlinger启动流程分析

在Android13版本中,SurfaceFlinger是由Android.bp去启动init.rc文件,然后再解析文件去加载SurfaceFlinger。上面方法主要处理如下:1、调用surfaceflinger的createSurfaceFlinger方法,实例化surfaceflinger。2、调用flinger(surfaceflinger)的init()方法,在客户端连接之前进行初始化。

liuning1985622的博客 1925

数据集FFHQ和LSUN介绍【包含FFHQ1024,515,256,128分辨率图像获取方法】

FFHQ全称Flickr-Faces-High-Quality(Flickr-Faces-HQ),最初是作为生成式对抗网络(GAN)的基准创建的,也用于StyleGAN的训练数据集中,并由英伟达于2019年开源。CVPR_2019Flickr-Faces-HQ (FFHQ)其由 70,000 张分辨率为 1024×1024 的高质量 PNG 图像组成,在年龄、种族和图像背景方面包含相当大的差异。它对眼镜、太阳镜、帽子等配饰也有很好的覆盖。

zik的博客 3988

LeetCode 218. The Skyline Problem

A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as

Index.html 1773

【系统架构设计师-2026上半年真题】案例分析-参考答案及详解(回忆版)

架构评估与设计:通过入侵检测系统的案例分析,阐述质量属性(性能/可用性/安全性/可修改性)的匹配方法,推荐管道-过滤器风格处理实时数据流,并设计8个核心构件实现数据采集到告警的全流程处理。 高并发优化方案: 分析悲观锁(排他锁/共享锁)与乐观锁的特性差异,提出乐观锁通过版本号/CAS实现,悲观锁适用于强一致性场景。 给出Redis优化三手段:分布式锁控制临界资源、Lua脚本保证原子操作、热点数据多级缓存,结合消息队列削峰填谷。 分层架构实践: 智

数据知道的博客 1755

【Leetcode】218. The Skyline Problem

题目地址: https://leetcode.com/problems/the-skyline-problem/ 给定若干大楼的左右边界及其高度(每个大楼都是矩形),大楼可能有重叠,要求返回一系列点的坐标表示这些大楼的边际线,这些点要从左向右输出,例如,对于相邻的两个点(a1,h1),(a2,h2)(a_1,h_1),(a_2,h_2)(a1​,h1​),(a2​,h2​),边际线的一部分是(a1,a2,h1)(a_1,a_2,h_1)(a1​,a2​,h1​),代表区间[a1,a2][a_1,a_2][a

数学、算法爱好者的博客 521

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

LeetCode-218. The Skyline Problem [C++][Java]

A city'sskylineis the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Given the locations and heights of all the buildings, returntheskylineformed by these buildings collectively.

贫道绝缘子的博客 500

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

LeetCode 218. The Skyline Problem(天际线)

原题网址:https://leetcode.com/problems/the-skyline-problem/ A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose y

James Pan 1634

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

leetcode 数组专题 06-leetcode.218 the-skyline-problem 力扣.218 天际线问题 扫描线

生成事件:每个建筑物的左边界和右边界都是一个事件,分别记录建筑物的 x 坐标和高度。排序事件:按 x 坐标排序,如果 x 坐标相同,左边界优先,高度高的左边界优先,右边界高的优先。处理事件:扫描线沿 x 轴从左到右扫描:遇到左边界,添加该建筑物的高度。遇到右边界,移除该建筑物的高度。如果当前的最大高度发生变化,记录关键点。输出结果:最终根据记录的关键点拼接出天际线。天际线问题本质上是一个典型的扫描线问题,通过对建筑物的左右边界进行扫描,并在每个扫描位置上更新当前的最大高度来获得天际线。

1586

[leetcode] 218.The Skyline Problem

题目: A city’s skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the building

u014673347的专栏 627

leetcode - 218. The Skyline Problem

leetcode - 218

sinat_41679123的博客 422

LeetCode(218):天际线问题 The Skyline Problem(Java)

2019.9.18 #程序员笔试必备# LeetCode 从零单刷个人笔记整理(持续更新) 这道智力题乍一看可以用动态规划处理,楼高从左至右类似一个入栈出栈的过程(但实际并不能用栈,因为出栈的楼高不一定在栈顶),而且每一次使用的“栈顶元素”是当前最高的楼高。那么只要能想到一种数据结构使之满足这种功能,那就可以想出动态规划的思路了。 动态规划 动态规划算法图解 这种数据结构可以是最大堆(删除复杂度...

NJU_ChopinXBP的博客 1020

[leetcode] 218. The Skyline Problem

Description A city’s skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the ...

Learning from the mistakes 282

LeetCode //C - 218. The Skyline Problem

【代码】LeetCode //C - 218. The Skyline Problem。

Made in Code 1179

Leetcode #218 The Skyline Problem

A city's skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as

王旻宇 542

LeetCode 218. The Skyline Problem(java)

A city’s skyline is the outer contour of the silhouette formed by all the buildings in that city when viewed from a distance. Now suppose you are given the locations and height of all the buildings as

katrina95的博客 1081

LeetCode——218. 天际线问题(The Skyline Problem)[困难]——分析及代码(Java)

LeetCode——218. 天际线问题[The Skyline Problem][困难]——分析及代码[Java]一、题目二、分析及代码1. 扫描线 + 优先队列(1)思路(2)代码(3)结果三、其他 一、题目 城市的天际线是从远处观看该城市中所有建筑物形成的轮廓的外部轮廓。给你所有建筑物的位置和高度,请返回由这些建筑物形成的 天际线 。 每个建筑物的几何信息由数组 buildings 表示,其中三元组 buildings[i] = [lefti, righti, heighti] 表示: lefti

江南土豆的博客 1891
上一篇: 21.1.27 LeetCode Determine if Two Strings Are Close Solution
下一篇: 21.1.29 LeetCode 1224. Maximum Equal Frequency
卷心菜_
博客等级 码龄6年 86粉丝 24原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值