---
# System prepended metadata

title: 'Leetcode [No. 452] Minimum Number of Arrows to Burst Balloons (MEDIUM) 解題心得'
tags: [leetcode]

---

# Leetcode [No. 452] Minimum Number of Arrows to Burst Balloons (MEDIUM) 解題心得

+ Daily Challenge solved on 2024/03/18

## 題目

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

## 思路
+ 這個題目其實我剛開始看到以為要做Merge Intervals了，但其實他也沒想像中複雜，他就只是要用數段的方式去檢查有沒有overlap而已
```c++=
class Solution {
public:
    int findMinArrowShots(vector<vector<int>>& points) {
        sort(points.begin(), points.end());
        int ans = 1;
        int prevEnd = points[0][1];
        for(int i = 1 ; i < points.size(); i++)
        {
            if(points[i][0] > prevEnd)
            {
                ans++;
                prevEnd = points[i][1];
            }
            else
            {
                prevEnd = min(prevEnd, points[i][1]);
            }
        }
        return ans;
    }
};
```

### 解法分析
+ time complexity: O(nlgn)


### 執行結果

![image](https://hackmd.io/_uploads/S1BsLBSC6.png)

### 值得參考的來源

https://home.gamer.com.tw/artwork.php?sn=5516126