There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided input is the start and end coordinates of the horizontal diameter. Since it's horizontal, y-coordinates don't matter and hence the x-coordinates of start and end of the diameter suffice. Start is always smaller than end. There will be at most 104 balloons.

An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with xstart and xend bursts by an arrow shot at x if xstart ≤ x ≤ xend. There is no limit to the number of arrows that can be shot. An arrow once shot keeps travelling up infinitely. The problem is to find the minimum number of arrows that must be shot to burst all balloons.

Example:

Input:
[[10,16], [2,8], [1,6], [7,12]] Output:
2 Explanation:
One way is to shoot one arrow for example at x = 6 (bursting the balloons [2,8] and [1,6]) and another arrow at x = 11 (bursting the other two balloons).
class Solution {
public int findMinArrowShots(int[][] points) {
if (points == null || points.length == 0) {
return 0;
}
Arrays.sort(points, (a, b) -> a[0] - b[0]);
int res = 1;
int end = points[0][1];
for (int i = 1; i < points.length; i++) {
if (points[i][0] > end) {
res += 1;
end = points[i][1];
} else {
end = Math.min(end, points[i][1]);
}
}
return res;
}
}

[LC] 452. Minimum Number of Arrows to Burst Balloons的更多相关文章

  1. 贪心:leetcode 870. Advantage Shuffle、134. Gas Station、452. Minimum Number of Arrows to Burst Balloons、316. Remove Duplicate Letters

    870. Advantage Shuffle 思路:A数组的最大值大于B的最大值,就拿这个A跟B比较:如果不大于,就拿最小值跟B比较 A可以改变顺序,但B的顺序不能改变,只能通过容器来获得由大到小的顺 ...

  2. 【LeetCode】452. Minimum Number of Arrows to Burst Balloons 解题报告(Python)

    [LeetCode]452. Minimum Number of Arrows to Burst Balloons 解题报告(Python) 标签(空格分隔): LeetCode 题目地址:https ...

  3. 452. Minimum Number of Arrows to Burst Balloons扎气球的个数最少

    [抄题]: There are a number of spherical balloons spread in two-dimensional space. For each balloon, pr ...

  4. [LeetCode] 452 Minimum Number of Arrows to Burst Balloons

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  5. 452. Minimum Number of Arrows to Burst Balloons——排序+贪心算法

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  6. 452. Minimum Number of Arrows to Burst Balloons

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  7. [LeetCode] 452. Minimum Number of Arrows to Burst Balloons 最少箭数爆气球

    There are a number of spherical balloons spread in two-dimensional space. For each balloon, provided ...

  8. 452 Minimum Number of Arrows to Burst Balloons 用最少数量的箭引爆气球

    在二维空间中有许多球形的气球.对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标.由于它是水平的,所以y坐标并不重要,因此只要知道开始和结束的x坐标就足够了.开始坐标总是小于结束坐标.平面 ...

  9. 【leetcode】452. Minimum Number of Arrows to Burst Balloons

    题目如下: 解题思路:本题可以采用贪心算法.首先把balloons数组按end从小到大排序,然后让第一个arrow的值等于第一个元素的end,依次遍历数组,如果arrow不在当前元素的start到en ...

随机推荐

  1. 【转】centos7轻松搭建文件服务器

    1.安装apache服务器 yum install httpd 2:启动httpd服务 service httpd start 3:查看httpd服务器的版本 4:修改访问端口和文件路径,以防端口冲突 ...

  2. ArchLinux安装(UEFI)

    ArchLinux安装(UEFI) 一.连接网络 1.连接 # wifi-menu 2.检查是否联通 (ctrl+c停止) # ping www.baidu.com 3.远程安装 注:连接上网络之后可 ...

  3. Neo4j--windows下安装neo4j

    参考 https://www.cnblogs.com/ljhdo/archive/2017/05/19/5521577.html 安装包下载 https://neo4j.com/download-ce ...

  4. Python快速安装库的靠谱办法

    我们如果使用python,并且使用pip安装一些库 会经常遇到pip在线安装速度慢 !   慢也就算了,安装经常会由于timeout等原因中断 所以有没有什么在线安装库并且速度较快的办法么? 其实是有 ...

  5. (转)绝对路径${pageContext.request.contextPath}用法及其与web.xml中Servlet的url-pattern匹配过程

    以系统的一个“添加商品”的功能为例加以说明,系统页面为add.jsp,如图一所示: 图一  添加商品界面 系统的代码目录结构及add.jsp代码如图二所示: 图二   系统的代码目录结构及add.js ...

  6. 转载:微信小程序源码提取反编译

    转载来源:www.51xuediannao.com/xiaochengxu/019c08cc.html 一.前言 微信小程序源码提取反编译,听起来很屌,其实还是简单的,基本是傻瓜式操作.要想拿到微信小 ...

  7. 24.docker 部署 wordPress

    1. 拉取远程 mysql 和 wordpress 镜像 并 启动起来 使用 docker pull mysql:5.7.27 docker pull wordpress 2. 创建mysql 的 c ...

  8. JS中,输出1-10之间的随机整数

    <script> document.write(parseInt(10*Math.random())); //输出0-10之间的随机整数 document.write(Math.floor ...

  9. 京东云数据库RDS SQL Server高可用概述

    数据库的高可用是指在硬件.软件故障发生时,可以将业务从发生故障的数据库节点迁移至备用节点.本文主要讲述SQL Server高可用方案,以及京东云RDS数据库的高可用实现. 一.高可用解决方案总览 1. ...

  10. 在scala命令行中加入类库

    在scala命令行中加入scala的类库. scala -toolcp $HOME/.ivy2/cache/org.scalanlp/breeze_2.12/jars/breeze_2.12-0.13 ...