Class Solution
java.lang.Object
g0401_0500.s0452_minimum_number_of_arrows_to_burst_balloons.Solution
452 - Minimum Number of Arrows to Burst Balloons.<p>Medium</p>
<p>There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array <code>points</code> where <code>points[i] = [x<sub>start</sub>, x<sub>end</sub>]</code> denotes a balloon whose <strong>horizontal diameter</strong> stretches between <code>x<sub>start</sub></code> and <code>x<sub>end</sub></code>. You do not know the exact y-coordinates of the balloons.</p>
<p>Arrows can be shot up <strong>directly vertically</strong> (in the positive y-direction) from different points along the x-axis. A balloon with <code>x<sub>start</sub></code> and <code>x<sub>end</sub></code> is <strong>burst</strong> by an arrow shot at <code>x</code> if <code>x<sub>start</sub> <= x <= x<sub>end</sub></code>. There is <strong>no limit</strong> to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path.</p>
<p>Given the array <code>points</code>, return <em>the <strong>minimum</strong> number of arrows that must be shot to burst all balloons</em>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> points = [[10,16],[2,8],[1,6],[7,12]]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> The balloons can be burst by 2 arrows:</p>
<ul>
<li>
<p>Shoot an arrow at x = 6, bursting the balloons [2,8] and [1,6].</p>
</li>
<li>
<p>Shoot an arrow at x = 11, bursting the balloons [10,16] and [7,12].</p>
</li>
</ul>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> points = [[1,2],[3,4],[5,6],[7,8]]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> One arrow needs to be shot for each balloon for a total of 4 arrows.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> points = [[1,2],[2,3],[3,4],[4,5]]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> The balloons can be burst by 2 arrows:</p>
<ul>
<li>
<p>Shoot an arrow at x = 2, bursting the balloons [1,2] and [2,3].</p>
</li>
<li>
<p>Shoot an arrow at x = 4, bursting the balloons [3,4] and [4,5].</p>
</li>
</ul>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= points.length <= 10<sup>5</sup></code></li>
<li><code>points[i].length == 2</code></li>
<li><code>-2<sup>31</sup> <= x<sub>start</sub> < x<sub>end</sub> <= 2<sup>31</sup> - 1</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findMinArrowShots
public int findMinArrowShots(int[][] points)
-