# 452. Minimum Number of Arrows to Burst Balloons

**<font color=red>难度: Medium</font>**

## 刷题内容

> 原题连接

* https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/

> 内容描述

```
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 10^4 balloons.

An arrow can be shot up exactly vertically from different points along the x-axis. A balloon with x_start and x_end bursts by an arrow shot at x if x_start ≤ x ≤ x_end. 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).

```

## 解题方案

> 思路 1
******- 时间复杂度: O(N*log(N))******- 空间复杂度: O(N)******


仔细观察可发现，一定存在一个发射点都在气球结束点的最优解。所以此题贪心可解，我们只要将气球结束点从小到大排列，对于每个气球，我们考虑这个气球能否被之前的发射点覆盖，如果不能我们就将当前气球的结束点当做新的发射点（发射点总数+1）。

beats 86.77%

```python
class Solution(object):
    def findMinArrowShots(self, points):
        """
        :type points: List[List[int]]
        :rtype: int
        """
        if not points or len(points) == 0:
            return 0
        
        points.sort(key = lambda x: x[1])
        end = points[0][1]
        res = 1
        for i, point in enumerate(points):
            if point[0] > end:
                res += 1
                end = point[1]
        return res
```
