#836
Rectangle Overlap
pupil · 480 · lc easy +27 · verified · 46.5% accepted · 2,087 likes · top 31%
Description
An axis-aligned rectangle is described by the list [x1, y1, x2, y2], where (x1, y1) is the bottom-left corner and (x2, y2) is the top-right corner. Its sides are parallel to the coordinate axes.
Two rectangles overlap if and only if their intersection has positive area. Rectangles that share only a corner or an edge do not overlap.
Given two axis-aligned rectangles rec1 and rec2, return true if they overlap, otherwise 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
Code
1
2
3