当前位置:网站首页>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);
};
边栏推荐
- LeetCode:221. 最大正方形
- Image,cv2读取图片的numpy数组的转换和尺寸resize变化
- C語言雙指針——經典題型
- pytorch查看张量占用内存大小
- Detailed explanation of dynamic planning
- 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
- 电脑F1-F12用途
- Mongodb installation and basic operation
- Super efficient! The secret of swagger Yapi
- Export IEEE document format using latex
猜你喜欢

Deep analysis of C language pointer

LeetCode:221. 最大正方形

Detailed explanation of dynamic planning
![[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born](/img/70/d275009134fcbf9ae984c0f278659e.jpg)
[today in history] February 13: the father of transistors was born The 20th anniversary of net; Agile software development manifesto was born

个人电脑好用必备软件(使用过)
![[embedded] print log using JLINK RTT](/img/22/c37f6e0f3fb76bab48a9a5a3bb3fe5.png)
[embedded] print log using JLINK RTT

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 language double pointer -- classic question type

ant-design的走马灯(Carousel)组件在TS(typescript)环境中调用prev以及next方法

Detailed explanation of heap sorting
随机推荐
Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
个人电脑好用必备软件(使用过)
704 binary search
Li Kou daily question 1 (2)
gcc动态库fPIC和fpic编译选项差异介绍
电脑清理,删除的系统文件
Excellent software testers have these abilities
如何正确截取字符串(例:应用报错信息截取入库操作)
Visual implementation and inspection of visdom
[MySQL] multi table query
角色动画(Character Animation)的现状与趋势
Alibaba cloud server mining virus solution (practiced)
LeetCode:剑指 Offer 48. 最长不含重复字符的子字符串
【剑指offer】序列化二叉树
How to effectively conduct automated testing?
超高效!Swagger-Yapi的秘密
Purpose of computer F1-F12
Swagger setting field required is mandatory
Current situation and trend of character animation
MySQL uninstallation and installation methods