当前位置:网站首页>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);
};
边栏推荐
- View computer devices in LAN
- LeetCode:41. 缺失的第一个正数
- Cesium draw points, lines, and faces
- TDengine 社区问题双周精选 | 第三期
- Double pointeur en langage C - - modèle classique
- Delay initialization and sealing classes
- 项目连接数据库遇到的问题及解决
- Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges
- Sublime text in CONDA environment plt Show cannot pop up the problem of displaying pictures
- [NVIDIA development board] FAQ (updated from time to time)
猜你喜欢
软件卸载时遇到trying to use is on a network resource that is unavailable
C语言深度解剖——C语言关键字
生成器参数传入参数
Restful API design specification
多元聚类分析
Delay initialization and sealing classes
Problems in loading and saving pytorch trained models
sublime text没关闭其他运行就使用CTRL+b运行另外的程序问题
Deep analysis of C language data storage in memory
查看局域网中电脑设备
随机推荐
同一局域网的手机和电脑相互访问,IIS设置
Double pointeur en langage C - - modèle classique
有效提高软件产品质量,就找第三方软件测评机构
ROS compilation calls the third-party dynamic library (xxx.so)
深度剖析C语言数据在内存中的存储
Navicat Premium 创建MySql 创建存储过程
LeetCode:221. 最大正方形
Mobile phones and computers on the same LAN access each other, IIS settings
Tcp/ip protocol
查看局域网中电脑设备
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语言双指针——经典题型
LeetCode:236. 二叉树的最近公共祖先
多元聚类分析
C语言深度解剖——C语言关键字
Detailed explanation of dynamic planning
企微服务商平台收费接口对接教程
Bitwise logical operator
SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
Generator parameters incoming parameters