当前位置:网站首页>LeetCode:836. Rectangle overlap
LeetCode:836. Rectangle overlap
2022-07-06 08:51:00 【Bertil】
Rectangle to list [x1, y1, x2, y2] Formal representation of , among (x1, y1) Is the coordinates of the lower left corner ,(x2, y2) It's the coordinates in the upper right corner . The upper and lower edges of the rectangle are parallel to x Axis , The left and right sides are parallel to y Axis .
If the area of intersection is just , It's called overlapping of two rectangles . Just to be clear , Two rectangles that only touch at the corner or edge do not form an overlap .
Give two rectangles rec1 and rec2 . If they overlap , return true; otherwise , return false .
Example 1:
Input :rec1 = [0,0,2,2], rec2 = [1,1,3,3]
Output :true
Example 2:
Input :rec1 = [0,0,1,1], rec2 = [1,0,2,1]
Output :false
Example 3:
Input :rec1 = [0,0,1,1], rec2 = [2,2,3,3]
Output :false
Tips :
rect1.length == 4
rect2.length == 4
-10^9 <= rec1[i], rec2[i] <= 10^9
rec1 and rec2 Represents a valid rectangle with a non-zero area
Their thinking
1. First, find out the four cases that do not overlap , It is represented by the horizontal and vertical coordinates of the lower left and upper right corners of the two figures
2. Then return the inverse operation results of these four cases
Code
/** * @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);
};
边栏推荐
- 角色动画(Character Animation)的现状与趋势
- Sublime text using ctrl+b to run another program without closing other runs
- [today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
- Compétences en mémoire des graphiques UML
- swagger设置字段required必填
- egg. JS getting started navigation: installation, use and learning
- Revit secondary development Hof method calls transaction
- Simple use of promise in uniapp
- 可变长参数
- 电脑F1-F12用途
猜你喜欢
pytorch训练好的模型在加载和保存过程中的问题
Navicat premium create MySQL create stored procedure
【嵌入式】使用JLINK RTT打印log
Esp8266-rtos IOT development
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
The harm of game unpacking and the importance of resource encryption
Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
[sword finger offer] serialized binary tree
Simple use of promise in uniapp
Tcp/ip protocol
随机推荐
Revit secondary development Hof method calls transaction
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
UML diagram memory skills
Cesium draw points, lines, and faces
LeetCode:836. 矩形重叠
Using pkgbuild:: find in R language_ Rtools check whether rtools is available and use sys The which function checks whether make exists, installs it if not, and binds R and rtools with the writelines
LeetCode:剑指 Offer 42. 连续子数组的最大和
sublime text中conda环境中plt.show无法弹出显示图片的问题
Tdengine biweekly selection of community issues | phase III
LeetCode:剑指 Offer 04. 二维数组中的查找
vb. Net changes with the window, scales the size of the control and maintains its relative position
Mongodb installation and basic operation
有效提高软件产品质量,就找第三方软件测评机构
Alibaba cloud server mining virus solution (practiced)
Computer graduation design PHP Zhiduo online learning platform
LeetCode:124. 二叉树中的最大路径和
Simple use of promise in uniapp
角色动画(Character Animation)的现状与趋势
可变长参数
[sword finger offer] serialized binary tree