[LeetCode] 850. Rectangle Area II 矩形面积之二

We are given a list of (axis-aligned)?rectangles.? Each?rectangle[i] = [x1, y1, x2, y2]?, where (x1, y1) are the coordinates of the bottom-left corner, and (x2, y2) are the coordinates of the top-right corner of the?ith rectangle.

Find the total area covered by all?rectangles?in the plane.? Since the answer?may be too large,?return it modulo 10^9 + 7.

Example 1:

Input: [[0,0,2,2],[1,0,2,3],[1,0,3,1]]
Output: 6
Explanation: As illustrated in the picture.

Example 2:

Input: [[0,0,1000000000,1000000000]]
Output: 49
Explanation: The answer is 10^18 modulo (10^9 + 7), which is (10^9)^2 = (-7)^2 = 49.

Note:

  • 1 <= rectangles.length <= 200
  • rectanges[i].length = 4
  • 0 <= rectangles[i][j] <= 10^9
  • The total area covered by all rectangles will never exceed?2^63 - 1?and thus will fit in a 64-bit signed integer.

Github 同步地址:

https://github.com/grandyang/leetcode/issues/850

类似题目:

Rectangle Area

参考资料:

https://leetcode.com/problems/rectangle-area-ii/

LeetCode All in One 题目讲解汇总(持续更新中...)

原文地址:https://www.cnblogs.com/grandyang/p/11371256.html

时间: 2024-10-16 09:06:25

[LeetCode] 850. Rectangle Area II 矩形面积之二的相关文章

LeetCode 850. Rectangle Area II

经典line sweep问题,和 perfect rectangle 很类似,但是要考虑多个矩形左边界一样的情况,加个id来区分. 和另一道类似的题 the skyline problem 不同的是,没有很多 corner cases,对 x 排序非常简单. 难点是在 active set 里,和 merge intervals 那题一样,计算 total_y,乘以两个相邻 event 的 delta_x. class Solution { public: struct interval { i

LeetCode 223 Rectangle Area(矩形面积)

翻译 找到在二维平面中两个相交矩形的总面积. 每一个矩形都定义了其左下角和右上角的坐标. (矩形例如以下图) 如果,总占地面积永远不会超过int的最大值. 原文 分析 这题前天试过,写了一堆推断.终究还是无果-- 贴几个别人的解决方式-- int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int64_t xmin1 = min( A, C ); int64_t xmax1 = max( A, C )

LeetCode:Rectangle Area - 矩形交叉部分的面积

1.题目名称 Rectangle Area(矩形交叉部分的面积) 2.题目地址 https://leetcode.com/problems/rectangle-area/ 3.题目内容 英文:Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown

[LeetCode]223. Rectangle Area矩形面积

/* 像是一道数据分析题 思路就是两个矩形面积之和减去叠加面积之和 */ public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { //求两个面积 int a1 = (C-A)*(D-B); int a2 = (G-E)*(H-F); //求叠加面积,(低上限-高下限)*(左右线-右左线) int h1 = Math.min(D,H); int h2 = Math.max(B,F); int

leetcode 223. Rectangle Area 计算面积---------- java

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. 计算

leetcode之Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. 这道

leetcode:Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. 本题

leetCode(33):Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. cl

【Leetcode】Rectangle Area

题目链接:https://leetcode.com/problems/rectangle-area/ 题目: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total are