题目要求:
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.
题目要求是求解所覆盖的面的之和;
这个题目实际上并不难,只是要找的计算量之间的逻辑关系即可
public class solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
//该题目使用求取对角式的方法进行处理
if(A == B && B == C && C == D) return (G - E) * (H - F);
if(E == F && F == G && G == H) return (C - A) * (D - B);
if(E >= C || A >= G || F >= D || B >= H) return (G - E) * (H - F) + (C - A) * (D - B);
int longx = Math.min(C, G) - Math.max(A, E);
int weightx = Math.min(D, H) - Math.max(B, F);
return (G - E) * (H - F) + (C - A) * (D - B) - longx * weightx;
}
}