LeetCode Rectangle Area

Description:

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.

Solution:

public class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G,
int H) {
return (C - A) * (D - B) + (G - E) * (H - F) - cover(A, C, E, G)
* cover(B, D, F, H);
}

int cover(int a, int b, int c, int d) {
if (a > c) {
int temp;

temp = a;
a = c;
c = temp;

temp = b;
b = d;
d = temp;
}
if (c >= b)
return 0;
if (d <= b)
return d - c;
return b - c;
}
}

leetcode 223: Rectangle Area

2015-06-10 03:25:56

leetcode -- Rectangle Area -- 看看计算公式

2015-12-03 12:46:36

【LeetCode-223】 Rectangle Area(C++)

2016-05-11 22:20:23

leetcode_question_85 Largest Rectangle in Histogram

2013-09-18 14:00:28

Leetcode_223_Rectangle Area

2015-07-13 22:02:28

LeetCode-Rectangle Area 解题报告

2015-06-29 22:09:12

Leetcode_85题：Maximal_Rectangle题解报告（C++）

2018-05-26 21:49:43

LeetCode: Largest Rectangle in Histogram(直方图最大面积)

2013-05-18 13:09:49

[C++]LeetCode: 133 Largest Rectangle in Histogram（最大矩形面积）

2015-02-04 21:01:20

LeetCode84 Largest Rectangle in Histogram java题解

2015-06-27 11:21:16