题目:3111. 覆盖所有点的最少矩形数目
思路:只需关注横坐标,对横坐标进行升序排序,然后进行贪心,求得最少的矩阵数量
class Solution {
public:
int minRectanglesToCoverPoints(vector<vector<int>>& points, int w) {
vector<int> v;
for(int i=0;i<points.size();i++){
v.push_back(points[i][0]);
}
sort(v.begin(),v.end());
int ans=1;
int last=v[0];
for(int i=1;i<v.size();i++){
if(v[i]-last>w){
ans++;
last=v[i];
}
}
return ans;
}
};
标签:last,int,points,3111,vector,ans,LeetCode,贪心
From: https://blog.csdn.net/weixin_46028214/article/details/140834425