https://leetcode.com/problems/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.
参考后(http://www.cnblogs.com/sunshisonghit/p/4580069.html)得到下面代码
public int ComputeArea(int A, int B, int C, int D, int E, int F, int G, int H)
{
int areaAB = (C - A) * (D - B) + (G - E) * (H - F);
int left = Math.Max(A, E);
int right = Math.Min(C, G);
int top = Math.Min(D, H);
int down = Math.Max(B, F);
if (left < right && down < top)
return areaAB - (right - left) * (top - down);
return areaAB;
}