当前位置:网站首页>LeetCode:836. 矩形重叠
LeetCode:836. 矩形重叠
2022-07-06 08:44:00 【Bertil】
矩形以列表 [x1, y1, x2, y2] 的形式表示,其中 (x1, y1) 为左下角的坐标,(x2, y2) 是右上角的坐标。矩形的上下边平行于 x 轴,左右边平行于 y 轴。
如果相交的面积为 正 ,则称两矩形重叠。需要明确的是,只在角或边接触的两个矩形不构成重叠。
给出两个矩形 rec1 和 rec2 。如果它们重叠,返回 true;否则,返回 false 。
示例 1:
输入:rec1 = [0,0,2,2], rec2 = [1,1,3,3]
输出:true
示例 2:
输入:rec1 = [0,0,1,1], rec2 = [1,0,2,1]
输出:false
示例 3:
输入:rec1 = [0,0,1,1], rec2 = [2,2,3,3]
输出:false
提示:
rect1.length == 4
rect2.length == 4
-10^9 <= rec1[i], rec2[i] <= 10^9
rec1 和 rec2 表示一个面积不为零的有效矩形
解题思路
1.首先找出不重叠的四种情况,以两图形左下角和右上角的横纵坐标进行表示
2。然后返回这四种情况的反运算结果即可
代码
/** * @param {number[]} rec1 * @param {number[]} rec2 * @return {boolean} */
var isRectangleOverlap = function(rec1, rec2) {
const [x1, y1, x2, y2] = rec1;
const [x3, y3, x4, y4] = rec2;
return !(x1 >= x4 || x3 >= x2 || y3 >= y2 || y1 >= y4);
};
边栏推荐
- Indentation of tabs and spaces when writing programs for sublime text
- Purpose of computer F1-F12
- Process of obtaining the electronic version of academic qualifications of xuexin.com
- Excellent software testers have these abilities
- Deep analysis of C language data storage in memory
- 游戏解包的危害及资源加密的重要性
- 深度剖析C语言数据在内存中的存储
- Bottom up - physical layer
- Shift Operators
- Revit secondary development Hof method calls transaction
猜你喜欢
Deep analysis of C language pointer
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
深度剖析C语言数据在内存中的存储
The harm of game unpacking and the importance of resource encryption
vb. Net changes with the window, scales the size of the control and maintains its relative position
Sort according to a number in a string in a column of CSV file
Trying to use is on a network resource that is unavailable
[MySQL] log
【ROS】usb_cam相机标定
MySQL learning records 12jdbc operation transactions
随机推荐
After PCD is converted to ply, it cannot be opened in meshlab, prompting error details: ignored EOF
LeetCode:387. 字符串中的第一个唯一字符
Report on Market Research and investment prospects of China's silver powder industry (2022 Edition)
【ROS】usb_cam相机标定
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
Unsupported operation exception
生成器参数传入参数
swagger设置字段required必填
Target detection - pytorch uses mobilenet series (V1, V2, V3) to build yolov4 target detection platform
LeetCode:剑指 Offer 42. 连续子数组的最大和
[NVIDIA development board] FAQ (updated from time to time)
sublime text中conda环境中plt.show无法弹出显示图片的问题
marathon-envs项目环境配置(强化学习模仿参考动作)
PC easy to use essential software (used)
[MySQL] log
TP-LINK 企业路由器 PPTP 配置
MySQL learning record 10getting started with JDBC
Tcp/ip protocol
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
LeetCode:124. 二叉树中的最大路径和