当前位置:网站首页>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);
};
边栏推荐
- [MySQL] limit implements paging
- 软件卸载时遇到trying to use is on a network resource that is unavailable
- Computer graduation design PHP Zhiduo online learning platform
- Leetcode: Sword Finger offer 42. Somme maximale des sous - tableaux consécutifs
- Navicat Premium 创建MySql 创建存储过程
- Light of domestic games destroyed by cracking
- 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
- @JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
- 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
猜你喜欢

Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)

Trying to use is on a network resource that is unavailable

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

C語言雙指針——經典題型

TP-LINK enterprise router PPTP configuration

项目连接数据库遇到的问题及解决
![[embedded] print log using JLINK RTT](/img/22/c37f6e0f3fb76bab48a9a5a3bb3fe5.png)
[embedded] print log using JLINK RTT

生成器参数传入参数

可变长参数

Chapter 1 :Application of Artificial intelligence in Drug Design:Opportunity and Challenges
随机推荐
LeetCode:26. 删除有序数组中的重复项
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
【ROS】usb_ Cam camera calibration
LeetCode:221. 最大正方形
C language double pointer -- classic question type
LeetCode:劍指 Offer 42. 連續子數組的最大和
[sword finger offer] serialized binary tree
UML图记忆技巧
[MySQL] multi table query
swagger设置字段required必填
Problems in loading and saving pytorch trained models
Bitwise logical operator
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
Swagger setting field required is mandatory
Unsupported operation exception
Target detection - pytorch uses mobilenet series (V1, V2, V3) to build yolov4 target detection platform
Double pointeur en langage C - - modèle classique
opencv+dlib实现给蒙娜丽莎“配”眼镜
Roguelike game into crack the hardest hit areas, how to break the bureau?
TP-LINK 企业路由器 PPTP 配置