391. Perfect Rectangle Hard

@problem@discussion
#Array#Line Sweep



1/**
2 * [391] Perfect Rectangle
3 *
4 * 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).
5 * Return true if all the rectangles together form an exact cover of a rectangular region.
6 *  
7 * Example 1:
8 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/27/perectrec1-plane.jpg" style="width: 300px; height: 294px;" />
9 * Input: rectangles = [[1,1,3,3],[3,1,4,2],[3,2,4,4],[1,3,2,4],[2,3,3,4]]
10 * Output: true
11 * Explanation: All 5 rectangles together form an exact cover of a rectangular region.
12 * 
13 * Example 2:
14 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/27/perfectrec2-plane.jpg" style="width: 300px; height: 294px;" />
15 * Input: rectangles = [[1,1,2,3],[1,3,2,4],[3,1,4,2],[3,2,4,4]]
16 * Output: false
17 * Explanation: Because there is a gap between the two rectangular regions.
18 * 
19 * Example 3:
20 * <img alt="" src="https://assets.leetcode.com/uploads/2021/03/27/perfecrrec4-plane.jpg" style="width: 300px; height: 294px;" />
21 * Input: rectangles = [[1,1,3,3],[3,1,4,2],[1,3,2,4],[2,2,4,4]]
22 * Output: false
23 * Explanation: Because two of the rectangles overlap with each other.
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= rectangles.length <= 2 * 10^4
29 * 	rectangles[i].length == 4
30 * 	-10^5 <= xi, yi, ai, bi <= 10^5
31 * 
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/perfect-rectangle/
36// discuss: https://leetcode.com/problems/perfect-rectangle/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41    pub fn is_rectangle_cover(rectangles: Vec<Vec<i32>>) -> bool {
42        false
43    }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_391() {
54    }
55}
56


Back
© 2025 bowen.ge All Rights Reserved.