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 left = max(A, E); int bottom = max(B, F); int right = min(C, G); int top = min(D, H); int shared = max(right - left, 0) * max(top - bottom, 0); int total = (D - B) * (C - A) + (H - F) * (G - E); return total - shared; } };