当前位置:网站首页>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);
};
边栏推荐
- Computer graduation design PHP Zhiduo online learning platform
- Sublime text using ctrl+b to run another program without closing other runs
- Simple use of promise in uniapp
- Leetcode刷题题解2.1.1
- LeetCode:214. 最短回文串
- Navicat premium create MySQL create stored procedure
- 如何正确截取字符串(例:应用报错信息截取入库操作)
- Compétences en mémoire des graphiques UML
- Delay initialization and sealing classes
- The network model established by torch is displayed by torch viz
猜你喜欢

Problems encountered in connecting the database of the project and their solutions

Roguelike game into crack the hardest hit areas, how to break the bureau?

C language double pointer -- classic question type

704 binary search

egg. JS project deployment online server
![[MySQL] multi table query](/img/eb/9d54df9a5c6aef44e35c7a63b286a6.jpg)
[MySQL] multi table query

广州推进儿童友好城市建设,将探索学校周边200米设安全区域

Unsupported operation exception

Image, CV2 read the conversion and size resize change of numpy array of pictures

LeetCode:124. 二叉树中的最大路径和
随机推荐
egg. JS getting started navigation: installation, use and learning
LeetCode:387. 字符串中的第一个唯一字符
Screenshot in win10 system, win+prtsc save location
Using C language to complete a simple calculator (function pointer array and callback function)
704 binary search
Leetcode刷题题解2.1.1
Navicat premium create MySQL create stored procedure
LeetCode:162. 寻找峰值
TP-LINK enterprise router PPTP configuration
Problems encountered in connecting the database of the project and their solutions
Indentation of tabs and spaces when writing programs for sublime text
Computer graduation design PHP Zhiduo online learning platform
Warning in install. packages : package ‘RGtk2’ is not available for this version of R
TCP/IP协议
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
How to conduct interface test? What are the precautions? Nanny level interpretation
Trying to use is on a network resource that is unavailable
Revit secondary development Hof method calls transaction
LeetCode:39. 组合总和
Philosophical enlightenment from single point to distributed