Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 87bf4ab

Browse files
committedMar 19, 2025
Add solution #836
1 parent 669c786 commit 87bf4ab

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@
643643
833|[Find And Replace in String](./0833-find-and-replace-in-string.js)|Medium|
644644
834|[Sum of Distances in Tree](./0834-sum-of-distances-in-tree.js)|Hard|
645645
835|[Image Overlap](./0835-image-overlap.js)|Medium|
646+
836|[Rectangle Overlap](./0836-rectangle-overlap.js)|Easy|
646647
841|[Keys and Rooms](./0841-keys-and-rooms.js)|Medium|
647648
844|[Backspace String Compare](./0844-backspace-string-compare.js)|Easy|
648649
846|[Hand of Straights](./0846-hand-of-straights.js)|Medium|

‎solutions/0836-rectangle-overlap.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 836. Rectangle Overlap
3+
* https://leetcode.com/problems/rectangle-overlap/
4+
* Difficulty: Easy
5+
*
6+
* An axis-aligned rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) is the
7+
* coordinate of its bottom-left corner, and (x2, y2) is the coordinate of its top-right corner.
8+
* Its top and bottom edges are parallel to the X-axis, and its left and right edges are parallel
9+
* to the Y-axis.
10+
*
11+
* Two rectangles overlap if the area of their intersection is positive. To be clear, two rectangles
12+
* that only touch at the corner or edges do not overlap.
13+
*
14+
* Given two axis-aligned rectangles rec1 and rec2, return true if they overlap, otherwise return
15+
* false.
16+
*/
17+
18+
/**
19+
* @param {number[]} rec1
20+
* @param {number[]} rec2
21+
* @return {boolean}
22+
*/
23+
var isRectangleOverlap = function(rec1, rec2) {
24+
const [x1, y1, x2, y2] = rec1;
25+
const [a1, b1, a2, b2] = rec2;
26+
return x1 < a2 && a1 < x2 && y1 < b2 && b1 < y2;
27+
};

0 commit comments

Comments
 (0)
Please sign in to comment.