class Solution {
public:
static bool cmp(vector<int>& a, vector<int>& b)
{
return a[0]<b[0];
}
int findMinArrowShots(vector<vector<int>>& points) {
//思路比较清晰了
//先将数组根据vector的首个数字进行排序操作
int len = points.size();
int count = 1;
if (len == 0)
return 0;
//排好序后进行算法操作
sort(points.begin(), points.end(), cmp);
//首先维护一个区间的数值[a,b]
//int a = 0, b = 0;
int a = points[0][0];
int b = points[0][1];
for (int i = 1; i < len; ++i)
{
vector<int> temp = points[i];
if (temp[0] <= b)//有重叠的
{
//都选取交集,就是选最小的
a = max(a, temp[0]);
b = min(b, temp[1]);
}
//没有重叠的话就进行重新选区间
else
{
++count;
a = temp[0];
b = temp[1];
}
}
return count;
}
};