leetCode(33):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.

class Solution {
public:
int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int area1=(C-A)*(D-B);
int area2=(G-E)*(H-F);
if(B>=H || F>=D || E>=C || G<=A)
{//如果不相交
return area1+area2;
}
else
{
int length,width;
width=min(C,G)-max(A,E);//宽
length=min(D,H)-max(B,F);//长
return area1+area2-length*width;//面积之和减去重合部分面积
}
}
};

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(c++)

2015-08-25 10:09:39

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

2015-02-04 21:01:20

Leetcode_223_Rectangle Area

2015-07-13 22:02:28

leetcode 223 Rectangle Area C++

2016-06-05 15:44:58

LeetCode84 Largest Rectangle in Histogram java题解

2015-06-27 11:21:16

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

2013-05-18 13:09:49

Leetcode 223 Rectangle Area 矩形区域面积

2015-08-28 17:51:41

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

2015-08-29 06:39:48

不良信息举报

leetCode(33):Rectangle Area