# [leetcode 223] Rectangle Area

Question:
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.

<span style="font-size:14px;">class Solution {
private:
int area(int height, int width){
return height*width;
}
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
/*int result;
int area1,area2,area3;
area1 = area(D-B,C-A);
area2 = area(H-F,G-E);

if(E < A && F < B && G > C && H > D)
return area2;
if(A < E && B < F && C > G && D > H)
return area1;
if(A == E && B == F && C == G && D == H)
return area1;
if(C < E || G < A || F > D || H < B)
return area1+area2;
vector<int> Xsort{A,C,E,G};
vector<int> Ysort{B,D,F,H};
sort(Xsort.begin(),Xsort.end());
sort(Ysort.begin(),Ysort.end());
area3 = area(Ysort[2]-Ysort[1], Xsort[2]-Xsort[1]);
return area1 + area2 - area3;*/
int area1 = (C-A)*(D-B);
int area2 = (G-E)*(H-F);
if(C<=E || G<=A || D<=F ||B>=H){
return area1+area2;
}
int width =  (A<=E)?min(C-E,G-E):min(C-A,G-A);
int height = (B>=F)?min(D-B,H-B):min(D-F,H-F);
return area1+area2-width*height;

}
};</span>

• 本文已收录于以下专栏：

## Leetcode_223_Rectangle Area

• pistolove
• 2015年07月13日 22:02
• 990

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

【223-Rectangle Area（矩形区域）】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】代码下载【https://github.com/Wang-Jun-Chao】原题...
• DERRANTCM
• 2015年08月29日 06:39
• 2717

## leetCode #223 Rectangle Area

• MarStarck
• 2015年08月11日 13:21
• 219

## (LeetCode 223) Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by...
• u014616233
• 2016年04月19日 21:58
• 441

## 【leetcode】【223】Rectangle Area

• xiaoliucool1314
• 2016年03月17日 10:11
• 176

## LeetCode(223)_Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is defined ...
• u011290316
• 2016年10月28日 16:35
• 94

## LeetCode 223 Rectangle Area

• Yano_nankai
• 2015年12月11日 09:01
• 278

## Rectangle Area - LeetCode 223

• bu_min
• 2015年06月08日 22:04
• 254

## leetcode 223: Rectangle Area

leetcode 223: Rectangle Area java c++ python
• xudli
• 2015年06月10日 03:25
• 8333

## LeetCode 223:Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is define...