# 【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.

c++代码（32ms，56.67%）

class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
if(C<E || G<A || H<B || D<F)
return (C-A)*(D-B)+(G-E)*(H-F);
else{
//算出长和高
int length,height; //长,高
if(A<=E && E<=C && C<=G)
length=C-E;
else if(A<=E && E<=G && G<=C)
length=G-E;
else if(E<=A && A<=G && G<=C)
length=G-A;
else
length=C-A;

if(D>=H && H>=B && B>=F)
height=H-B;
else if(D>=H && H>=F && F>=B)
height=H-F;
else if(H>=D && D>=F && F>=B)
height=D-F;
else
height=D-B;

return (C-A)*(D-B)+(G-E)*(H-F)-length*height;

}

}
};

int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int left = max(A,E), right = max(min(C,G), left);
int bottom = max(B,F), top = max(min(D,H), bottom);
return (C-A)*(D-B) - (right-left)*(top-bottom) + (G-E)*(H-F);
}

#### leetcode 223: Rectangle Area

2015-06-10 03:25:56

#### Leetcode_223_Rectangle Area

2015-07-13 22:02:28

#### 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-10-11 23:02:06

#### [leetcode]223. Rectangle Area

2016-11-10 21:25:02

#### LeetCode : 223. Rectangle Area

2016-08-30 16:02:19

#### Leetcode 223. Rectangle Area

2016-09-13 03:26:25

#### LeetCode 223. Rectangle Area

2016-04-19 10:23:31