Rectangle Area
Thoughts
Code
class Solution {
public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
int overlapping = 0;
int left = Math.max(A, E), right = Math.min(C, G);
int bottom = Math.max(B, F), top = Math.min(D, H);
if (right > left && top > bottom) {
overlapping = (right - left) * (top - bottom);
}
return (C - A) * (D - B) + (G - E) * (H - F) - overlapping;
}
}Analysis
Last updated