title: 452. Minimum Number of Arrows to Burst Balloons
tags:
- greedy
categories: leetcode
comments: false
class Solution {
public:
int findMinArrowShots(vector<vector<int>>& points) {
sort(points.begin(), points.end(), [](vector<int>& a, vector<int>& b){
return a[1]<b[1];
});
int n = points.size(), count = 1, end = points[0][1];
for(int i=1;i<n;++i){
vector<int>& cur = points[i];
// åééį觸įĸ°äšįŽéį
// ä¸éįįæŗ
if(end < cur[0]){
count++;
end = cur[1];
}
}
return count;
}
};
- time complexity
O(nlogn)
- speed complexity
O(1)