当前位置:网站首页>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);
};
边栏推荐
- SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
- [NVIDIA development board] FAQ (updated from time to time)
- LeetCode:剑指 Offer 03. 数组中重复的数字
- Light of domestic games destroyed by cracking
- PC easy to use essential software (used)
- swagger设置字段required必填
- LeetCode:剑指 Offer 42. 连续子数组的最大和
- TP-LINK 企业路由器 PPTP 配置
- LeetCode:387. 字符串中的第一个唯一字符
- UML圖記憶技巧
猜你喜欢
![[embedded] print log using JLINK RTT](/img/22/c37f6e0f3fb76bab48a9a5a3bb3fe5.png)
[embedded] print log using JLINK RTT

Swagger setting field required is mandatory

TCP/IP协议

After reading the programmer's story, I can't help covering my chest...

SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date

UML图记忆技巧

深度剖析C语言数据在内存中的存储

visdom可视化实现与检查介绍

Alibaba cloud server mining virus solution (practiced)

Indentation of tabs and spaces when writing programs for sublime text
随机推荐
力扣每日一题(二)
Mobile phones and computers on the same LAN access each other, IIS settings
Problems encountered in connecting the database of the project and their solutions
LeetCode:498. 对角线遍历
目标检测——Pytorch 利用mobilenet系列(v1,v2,v3)搭建yolov4目标检测平台
Trying to use is on a network resource that is unavailable
Esp8266-rtos IOT development
The harm of game unpacking and the importance of resource encryption
TCP/IP协议
有效提高软件产品质量,就找第三方软件测评机构
数学建模2004B题(输电问题)
[MySQL] limit implements paging
TDengine 社区问题双周精选 | 第三期
vb.net 随窗口改变,缩放控件大小以及保持相对位置
随手记01
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
ESP8266-RTOS物联网开发
Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges
Computer graduation design PHP Zhiduo online learning platform
What is the role of automated testing frameworks? Shanghai professional third-party software testing company Amway