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 ...
随机推荐
- HLog工作原理
- JQuery--漂亮的三目运算与jQ选择器结合代码
$(function($) { $("input[name='timeset']").bind('click', function() { $(this).val() == 'cu ...
- mysql大数据表优化
1.应尽量避免在 where 子句中使用!=或<>操作符,否则将引擎放弃使用索引而进行全表扫描. 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉 ...
- [转]SQLserver字符串分割函数
一.按指定符号分割字符串,返回分割后的元素个数,方法很简单,就是看字符串中存在多少个分隔符号,然后再加一,就是要求的结果. CREATE function Get_StrArrayLength ( ) ...
- 第03章 科学计算库Numpy
016.Numpy数据结构 关于矩阵运算的库 矩阵 017.Numpy基本操作 判断每一个元素的 018.Numpy矩阵属性 019.Numpy矩阵操作 020.Numpy常用函数 按列拼接就用 ...
- LuoguP3690 【模板】Link Cut Tree (动态树) LCT模板
P3690 [模板]Link Cut Tree (动态树) 题目背景 动态树 题目描述 给定n个点以及每个点的权值,要你处理接下来的m个操作.操作有4种.操作从0到3编号.点从1到n编号. 0:后接两 ...
- create user
create创建的用户,只有usage权限,即,连接数据库的权限,最低的权限. # 1.新建用户,这里的用户是由user_name 和ip一起唯一确定一个用户.# 2.若省略ip表达式,则表示%,即所 ...
- [Array]628. Maximum Product of Three Numbers
Given an integer array, find three numbers whose product is maximum and output the maximum product. ...
- c++设计模式:代理模式
代理模式的实现和visitor实现有一曲同工之妙.这里就不多说了,也是实现set_delegate接口,以及回调函数处理接口. 主要区别在于: visitor主要是把信息回调之后就不管了. 代理模式主 ...
- python打包成为exe文件
pyinstaller 库的使用 PyInstaller是一个十分有用的第三方库,它能够在Windows.Linux.Mac OS X 等操作系统下将 Python 源文件打包,通过对源文件打包,Py ...