题目来源
这道题感觉不难,先排个序,然后从左向右扫描,保存扫描过的气球最大左边界和最小右边界,当最大左边界小于最小右边界时,需要射一箭。
class Solution {
public:
int findMinArrowShots(vector<pair<int, int>>& points) {
sort(points.begin(), points.end());
int n = points.size(), res = 0;
for (int i=0; i<n; i++) {
int left_max = points[i].first, right_min = points[i].second;
while (left_max <= right_min) {
i++;
left_max = max(left_max, points[i].first);
right_min = min(right_min, points[i].second);
}
i--;
res++;
}
return res;
}
};