标签:ima mamicode for min leetcode else tar pre strong
题目链接:用最少数量的箭引爆气球
题目描述:
题解:
class Solution {
public:
static bool cmp(vector<int> &a, vector<int> &b) //按右边界排序
{
return a[1] < b[1];
}
int findMinArrowShots(vector<vector<int>>& points) {
if(points.size() == 0)
return 0;
sort(points.begin(), points.end(), cmp);
int result = 1;
for(int i = 1; i < points.size(); i++)
{
if(points[i][0] > points[i - 1][1]) //当前节点的左边界与前一个节点的右边界不重叠
result++;
else{ //更新当前节点的右边界为最小右边界
points[i][1] = points[i - 1][1];
}
}
return result;
}
};
标签:ima mamicode for min leetcode else tar pre strong
原文地址:https://www.cnblogs.com/ZigHello/p/14943274.html