Leetcode836.Rectangle Overlap矩阵重叠
矩形以列表 [x1, y1, x2, y2] 的形式表示,其中 (x1, y1) 为左下角的坐标,(x2, y2) 是右上角的坐标。
如果相交的面积为正,则称两矩形重叠。需要明确的是,只在角或边接触的两个矩形不构成重叠。
给出两个矩形,判断它们是否重叠并返回结果。
示例 1:
输入:rec1 = [0,0,2,2], rec2 = [1,1,3,3] 输出:true
示例 2:
输入:rec1 = [0,0,1,1], rec2 = [1,0,2,1] 输出:false
说明:
- 两个矩形 rec1 和 rec2 都以含有四个整数的列表的形式给出。
- 矩形中的所有坐标都处于 -10^9 和 10^9 之间。
如何判断两条线段是否重叠,给定两条线段的起始点(left1,right1)和结束点(left2,right2)。
如果两条线段重叠,那么必然有某个x满足max(left1,left2)<x<min(right1,righ2)。
矩阵同理,注意题目说的只在角或边接触的不构成重叠
class Solution {
public:
bool isRectangleOverlap(vector<int>& rec1, vector<int>& rec2) {
int x1 = max(rec1[0], rec2[0]);
int y1 = max(rec1[1], rec2[1]);
int x2 = min(rec1[2], rec2[2]);
int y2 = min(rec1[3], rec2[3]);
if(x1 >= x2 || y1 >= y2)
return false;
return true;
}
};
Leetcode836.Rectangle Overlap矩阵重叠的更多相关文章
- [LeetCode] Rectangle Overlap 矩形重叠
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
- 836. Rectangle Overlap 矩形重叠
[抄题]: A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of i ...
- 【Leetcode_easy】836. Rectangle Overlap
problem 836. Rectangle Overlap solution: class Solution { public: bool isRectangleOverlap(vector< ...
- 836. Rectangle Overlap ——weekly contest 85
Rectangle Overlap A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coor ...
- [Swift]LeetCode836. 矩形重叠 | Rectangle Overlap
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
- [LeetCode] Image Overlap 图像重叠
Two images A and B are given, represented as binary, square matrices of the same size. (A binary ma ...
- #Leetcode# 836. Rectangle Overlap
https://leetcode.com/problems/rectangle-overlap/ A rectangle is represented as a list [x1, y1, x2, y ...
- [LeetCode&Python] Problem 836. Rectangle Overlap
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
- LeetCode - Rectangle Overlap
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bot ...
随机推荐
- Hbase实验:java创建和删除table
开启zookeeper.hadoop.hbase: 打开eclipse创一个java project,然后导入所需jar包: 写好java代码,运行create,然后去hbase shell里查看: ...
- 快速体验 Sentinel 集群限流功能,只需简单几步
️ Pic by Alibaba Tech on Facebook 集群限流 可以限制某个资源调用在集群内的总 QPS,并且可以解决单机流量不均导致总的流控效果不佳的问题,是保障服务稳定性的利器. S ...
- Java开源诊断工具 Arthas 发布v3.1.0
Arthas 自2018年9月份上线以来「传送门」,已收获近万个star,感谢开发者们的认可.此次Arthas 3.1.0版本的发布,不仅带来大家投票出来的新LOGO,还带来强大的新功能和更好的易用性 ...
- bzoj1706 relays 奶牛接力跑 线性代数
题目描述 FJ的N(2 <= N <= 1,000,000)头奶牛选择了接力跑作为她们的日常锻炼项目.至于进行接力跑的地点 自然是在牧场中现有的T(2 <= T <= 100) ...
- python 运行python -m pip list 出现错误
1.出现如下错误提示 2解决方案 解决方法:(windows)在C:\Users{用户名}\ 目录下创建名称为pip的文件夹,里面创建文本文件,内容为 [list] format=columns 保存 ...
- 矩阵快速幂2 3*n铺方格
#include <iostream> #include <cstdlib> #include <cstring> #include <queue> # ...
- PAT甲级——A1059 Prime Factors
Given any positive integer N, you are supposed to find all of its prime factors, and write them in t ...
- 数据表中记录明明有,session.get(类.class, id);返回null
出现null的处理思路首先检查数据库中是否真的有这个记录 确实存在的,用接口查一下最大值,也是存在的,数据库连接正常 写sql也可以查得到 然而诡异的事情出现了 难道是一直在用的dao代码出了问题? ...
- 学习Python笔记---变量和简单数据类型
首先声明,这个是个人在自学的一些笔记,因为是小白,刚接触Python,之前也没有过类似的经验,所以很多东西对于其他人来说可能是小白级别的,写出来没有其他的意思就是自己整理然后记录一下,顺便分享出来,而 ...
- react高阶函数组件
Layout as a Higher Order Component // components/MyLayout.js import Header from './Header'; const la ...