223. Rectangle Area
Last updated
Last updated
/**
* Time complexity :
* Space complexity :
*/
class Solution {
public int computeArea(int A, int B, int C, int D,
int E, int F, int G, int H) {
int totalArea = (G-E) * (H-F) + (C-A) * (D-B);
if(C < E || G < A || H < B || D < F) {
return totalArea;
}
int left = Math.max(A, E);
int right = Math.min(C, G);
int top = Math.min(D, H);
int bottom = Math.max(F, B);
return totalArea - ((right-left) * (top-bottom));
}
}