class Solution {
public:
static const bool cmp (vector<int> &a, vector<int> &b) {
return a[1] < b[1];
}
int findMinArrowShots(vector<vector<int>>& points) {
int n = points.size();
sort(points.begin(), points.end(), cmp);
int ans = 0;
int idx = 0;
while (idx < n) {
int last = points[idx][1];
ans += 1;
while (idx < n && points[idx][0] <= last && last <= points[idx][1]) idx += 1;
}
return ans;
}
};
Time Complexity: O(nlogn)
Space: O(1)
感受一下 sort + gready 的題目,這題就是很明顯的 gready 了