
g0301_0400.s0391_perfect_rectangle.readme.md Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
391\. Perfect Rectangle
Hard
Given an array `rectangles` where rectangles[i] = [xi, yi, ai, bi]
represents an axis-aligned rectangle. The bottom-left point of the rectangle is (xi, yi)
and the top-right point of it is (ai, bi)
.
Return `true` _if all the rectangles together form an exact cover of a rectangular region_.
**Example 1:**

**Input:** rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]
**Output:** true
**Explanation:** All 5 rectangles together form an exact cover of a rectangular region.
**Example 2:**

**Input:** rectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]
**Output:** false
**Explanation:** Because there is a gap between the two rectangular regions.
**Example 3:**

**Input:** rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[3,2,4,4]]
**Output:** false
**Explanation:** Because there is a gap in the top center.
**Example 4:**

**Input:** rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[2,2,4,4]]
**Output:** false
**Explanation:** Because two of the rectangles overlap with each other.
**Constraints:**
* 1 <= rectangles.length <= 2 * 104
* `rectangles[i].length == 4`
* -105 <= xi, yi, ai, bi <= 105
© 2015 - 2025 Weber Informatics LLC | Privacy Policy