3111. 覆盖所有点的最少矩形数目

3111. 覆盖所有点的最少矩形数目


题目链接:3111. 覆盖所有点的最少矩形数目

代码如下:

cpp 复制代码
class Solution 
{
public:
	int minRectanglesToCoverPoints(vector<vector<int>>& points, int w)
	{
		sort(points.begin(), points.end(), [](const auto& a, const auto& b)->bool
			{
				return a[0] < b[0];//升序排序
			});
		int res = 0;
		int x2 = -1;
		for (const auto& p : points)
		{
			if (p[0] > x2)
			{
				res++;
				x2 = p[0] + w;
			}
		}
		return res;
	}
};
相关推荐
Android小码家1 小时前
Vehicle 实战 自定义属性+测试demo
java·c++·framework·vhal·vehicle
hetao17338371 小时前
2026-10-19 hetao1733837 的刷题记录
c++·算法
夏虫不可与之言冰1 小时前
第三课 点亮 LED 与定时器非阻塞闪烁
c语言·c++·vscode·单片机·嵌入式硬件·物联网
辛苦才能1 小时前
C++ 哈希表深度解析:删除为什么必须打标记,负载因子为什么卡 0.7
开发语言·数据结构·c++·算法
miller-tsunami1 小时前
STL简介&string相关知识点
开发语言·c++·string
坤坤子吖2 小时前
Linux 线程同步与互斥——互斥锁
linux·服务器·c++·笔记·学习
TDTC_XQ2 小时前
Linux网络编程accept的讲解
linux·服务器·c++
FlightYe2 小时前
音视频修炼之容器与协议(一):MP4和MOV的box剖析
android·linux·c++·ffmpeg·音视频
音草3 小时前
AVL 树详解:从概念到 C++ 实现
c++
凉茶钱3 小时前
list:哨兵节点,const_iterator 和 const iterator的区别与迭代器失效
数据结构·c++·list