当前位置:网站首页>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);
};
边栏推荐
- Cesium draw points, lines, and faces
- R language ggplot2 visualization: place the title of the visualization image in the upper left corner of the image (customize Title position in top left of ggplot2 graph)
- SAP ui5 date type sap ui. model. type. Analysis of the parsing format of date
- 超高效!Swagger-Yapi的秘密
- 自动化测试框架有什么作用?上海专业第三方软件测试公司安利
- 多元聚类分析
- Excellent software testers have these abilities
- visdom可视化实现与检查介绍
- 深度剖析C语言指针
- UnsupportedOperationException异常
猜你喜欢

pytorch训练好的模型在加载和保存过程中的问题

Using C language to complete a simple calculator (function pointer array and callback function)

Fairguard game reinforcement: under the upsurge of game going to sea, game security is facing new challenges

Current situation and trend of character animation

Light of domestic games destroyed by cracking
![[sword finger offer] serialized binary tree](/img/e2/25c9322da3acda06c4517b0c50f81e.png)
[sword finger offer] serialized binary tree

Detailed explanation of heap sorting

Cesium draw points, lines, and faces

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

【剑指offer】序列化二叉树
随机推荐
Variable length parameter
Tcp/ip protocol
Analysis of the source code of cocos2d-x for mobile game security (mobile game reverse and protection)
Sublime text using ctrl+b to run another program without closing other runs
MYSQL卸载方法与安装方法
Image,cv2读取图片的numpy数组的转换和尺寸resize变化
UML diagram memory skills
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born
egg. JS directory structure
LeetCode:394. 字符串解码
Deep analysis of C language pointer
LeetCode:39. 组合总和
Crash problem of Chrome browser
@JsonBackReference和@JsonManagedReference(解决对象中存在双向引用导致的无限递归)
企微服务商平台收费接口对接教程
After reading the programmer's story, I can't help covering my chest...
TCP/IP协议
swagger设置字段required必填
sublime text的编写程序时的Tab和空格缩进问题
pytorch训练好的模型在加载和保存过程中的问题