当前位置:网站首页>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);
};
边栏推荐
- Warning in install. packages : package ‘RGtk2’ is not available for this version of R
- Problems in loading and saving pytorch trained models
- Deep analysis of C language data storage in memory
- LeetCode:836. 矩形重叠
- Nacos 的安装与服务的注册
- Revit 二次开发 HOF 方式调用transaction
- 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)
- LeetCode:236. 二叉树的最近公共祖先
- LeetCode:387. 字符串中的第一个唯一字符
- 角色动画(Character Animation)的现状与趋势
猜你喜欢

MongoDB 的安装和基本操作

软件卸载时遇到trying to use is on a network resource that is unavailable

深度剖析C语言数据在内存中的存储

win10系统中的截图,win+prtSc保存位置

如何正确截取字符串(例:应用报错信息截取入库操作)

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

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

个人电脑好用必备软件(使用过)

TCP/IP协议

PC easy to use essential software (used)
随机推荐
Leetcode刷题题解2.1.1
Leetcode: Sword finger offer 42 Maximum sum of continuous subarrays
Marathon envs project environment configuration (strengthen learning and imitate reference actions)
[Hacker News Weekly] data visualization artifact; Top 10 Web hacker technologies; Postman supports grpc
Revit secondary development Hof method calls transaction
The harm of game unpacking and the importance of resource encryption
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)
优秀的软件测试人员,都具备这些能力
Bitwise logical operator
CSP first week of question brushing
Computer graduation design PHP Zhiduo online learning platform
Export IEEE document format using latex
Navicat premium create MySQL create stored procedure
Li Kou daily question 1 (2)
After PCD is converted to ply, it cannot be opened in meshlab, prompting error details: ignored EOF
[embedded] cortex m4f DSP Library
Niuke winter vacation training 6 maze 2
【ROS】usb_ Cam camera calibration
Roguelike game into crack the hardest hit areas, how to break the bureau?
Simple use of promise in uniapp