1. 程式人生 > >Leetcode 452. 用最少數量的箭引爆氣球

Leetcode 452. 用最少數量的箭引爆氣球

else leet gin find vector con auto bsp amp

class Solution {
public:
    int findMinArrowShots(vector<pair<int, int>>& points) {
        if(points.size()==0)
            return 0;
        
        sort(points.begin(), points.end(), [](const auto a, const auto b){
                                                                            
return a.first < b.first; }); int short_num = 1; int short_beg = points[0].first; int short_end = points[0].second; for(int i=1; i<points.size(); ++i) { if(points[i].first <= short_end) { short_beg
= points[i].first; if(short_end > points[i].second) short_end = points[i].second; } else { ++short_num; short_beg = points[i].first; short_end = points[i].second; } }
return short_num; } };

Leetcode 452. 用最少數量的箭引爆氣球