452. Minimum Number of Arrows to Burst Balloons Medium
1/**
2 * [452] Minimum Number of Arrows to Burst Balloons
3 *
4 * There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diameter stretches between xstart and xend. You do not know the exact y-coordinates of the balloons.
5 * Arrows can be shot up directly vertically (in the positive y-direction) from different points along the x-axis. A balloon with xstart and xend is burst by an arrow shot at x if xstart <= x <= xend. There is no limit to the number of arrows that can be shot. A shot arrow keeps traveling up infinitely, bursting any balloons in its path.
6 * Given the array points, return the minimum number of arrows that must be shot to burst all balloons.
7 *
8 * Example 1:
9 *
10 * Input: points = [[10,16],[2,8],[1,6],[7,12]]
11 * Output: 2
12 * Explanation: The balloons can be burst by 2 arrows:
13 * - Shoot an arrow at x = 6, bursting the balloons [2,8] and [1,6].
14 * - Shoot an arrow at x = 11, bursting the balloons [10,16] and [7,12].
15 *
16 * Example 2:
17 *
18 * Input: points = [[1,2],[3,4],[5,6],[7,8]]
19 * Output: 4
20 * Explanation: One arrow needs to be shot for each balloon for a total of 4 arrows.
21 *
22 * Example 3:
23 *
24 * Input: points = [[1,2],[2,3],[3,4],[4,5]]
25 * Output: 2
26 * Explanation: The balloons can be burst by 2 arrows:
27 * - Shoot an arrow at x = 2, bursting the balloons [1,2] and [2,3].
28 * - Shoot an arrow at x = 4, bursting the balloons [3,4] and [4,5].
29 *
30 *
31 * Constraints:
32 *
33 * 1 <= points.length <= 10^5
34 * points[i].length == 2
35 * -2^31 <= xstart < xend <= 2^31 - 1
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/
41// discuss: https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn find_min_arrow_shots(points: Vec<Vec<i32>>) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_452() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.