clueless coding // TODO: be smarter

LeetCode Rectangle Area: CPP Solution



TL;DR Code Solution


int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
    int total = (C-A) * (D-B) + (G-E) * (H-F);

    if (E>=C || F>=D || G<=A || H<=B) {
        return total;
    }

    return total - (min(C,G) - max(A,E)) * (min(D,H) - max(B,F));
}