# Rectangle Area - LeetCode 223

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.

Rectangle Area

Assume that the total area is never beyond the maximum possible value of int.
Credits:
Special thanks to @mithmatt for adding this problem, creating the above image and all test cases.

Hide Tags Math

较小纵坐标down是两个矩形各对应小纵坐标的较大值
较小横坐标lef是是两个矩形各对应小横坐标的较大值
较大横坐标rig是是两个矩形各对应大横坐标的较小值

/**////////////////0ms*/
class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int a = 0, b = 0,c = 0;
a = (C - A)*(D - B);
b = (G - E)*(H - F);
if(C <= E || A  >= G || B >= H ||F >=D ) //不相交
{
return a+b;
}
//相交，求出交叉矩形的边长
int up = min(H,D);
int down = max(B,F);
int lef = max(A,E);
int rig = min(G,C);

c = (up-down) * (rig - lef); //交叉矩形的面积

return a + b - c;
}
};

#### 【OpenJudge】矩形分割——（二分查找）

2016-10-12 10:25:30

#### C++设计并测试一个名为Rectangle的矩形类，其属性为矩形的左下角与右下角两个点的坐标，根据坐标计算矩形的面积

2017-12-26 19:25:35

#### 网易2019：矩形重叠

2018-03-31 18:31:36

#### 线段树求矩形面积并 方法详解 （扫描线）HDU 1542 & HDU 3265 & POJ 1151

2015-01-26 22:07:31

#### [2019网易实习编程题]矩形重叠

2018-03-31 14:55:06

#### leetcode 223: Rectangle Area

2015-06-10 03:25:56

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

2016-05-11 22:20:23

#### Leetcode_223_Rectangle Area

2015-07-13 22:02:28

#### 223. Rectangle Area [easy] (Python)

2016-06-15 11:24:21

#### Leetcode 223 Rectangle Area 矩形区域面积

2015-08-28 17:51:41