An akward C solution


  • 0
    H
    int computeOverlap(int A, int B, int C, int D, int E, int F, int G, int H) {
        if(A > E) return computeOverlap(E,B,G,D,A,F,C,H);
        if(B > F) return computeOverlap(A,F,C,H,E,B,G,D);
        int width, height;
        width = ((C < G ? C : G) - E) * (E < C);
        height = ((D < H ? D : H) - F) * (F < D);
        return width * height;
    }
    
    int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        return (C - A) * (D - B) + (G - E) * (H - F) - computeOverlap(A,B,C,D,E,F,G,H);
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.