###### LeetCode : 223. 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.

1.判断是否相交

2.求出相交矩形的面积。

AC代码如下：

 int computeArea(int A, int B, int C, int D, int E, int F, int G, int H)
{
if(!IsInsection( A, B, C, D, E, F, G, H))
return (C-A)*(D-B)+(G-E)*(H-F);
else
return (C-A)*(D-B)+(G-E)*(H-F) - InsectionArea( A, B, C, D, E, F, G, H);
}
bool IsInsection(int A, int B, int C, int D, int E, int F, int G, int H)//判断两个矩形是否相交
{
if(D < F || C < E || H < B || G < A)
return false;
else
return true;
}
int InsectionArea(int A, int B, int C, int D, int E, int F, int G, int H)//相交矩形的面积
{
int minx = max(A,E);
int miny = max(B,F);
int maxx = min(C,G);
int maxy = min(D,H);
return (maxx - minx)*(maxy - miny);
}

#### leetcode 223: Rectangle Area

2015-06-10 03:25:56

#### [leetcode-223]Rectangle Area(c++)

2015-08-25 10:09:39

#### Leetcode_223_Rectangle Area

2015-07-13 22:02:28

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

2016-05-11 22:20:23

#### leetcode 223 Rectangle Area C++

2016-06-05 15:44:58

#### [LeetCode 223] Rectangle Area

2015-09-24 03:27:17

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

2015-08-28 17:51:41

#### 【LeetCode-面试算法经典-Java实现】【223-Rectangle Area（矩形区域）】

2015-08-29 06:39:48

#### 223. Rectangle Area LeetCode

2016-02-12 12:34:51

#### [leetcode]223. Rectangle Area

2016-11-10 21:25:02

## 不良信息举报

LeetCode : 223. Rectangle Area