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; } };
原文地址:https://www.cnblogs.com/randyniu/p/9334861.html
时间: 2024-10-10 18:49:48