Topic:
Find the total area covered by and rectilinear rectangles in a 2D plane.
Each rectangle was defined by its bottom left corner and top right corner as shown in the figure.
Assume the total area is never beyond the maximum possible value of int.
First determine whether two rectangles intersect, do not intersect directly return two rectangular area, the intersection needs to calculate the intersection of the lower left and right points of the coordinates, with two rectangular area minus the intersection area can be.
classSolution { Public: intComputearea (intAintBintCintDintEintFintGintH) {intRecarea = Area (a,b,c,d) +Area (E,F,G,H); if(A >= G | | C <= E | | D <= F | | B >= H)returnRecarea; intRecminx =Max (a,e); intRecminy =Max (b,f); intRecmaxx =min (c,g); intRecmaxy =min (d,h); returnRecarea-Area (Recminx, Recminy, Recmaxx, Recmaxy); } intAreaintAintBintCintD) { return(c-a) * (dc); }};
"Leetcode" 223. Rectangle Area Problem Solving Summary