Beats 94.56%, 28ms, 3 lines, c++ solution


  • 4
    int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int s = (C-A) * (D-B) + (G-E) * (H-F); // areas of the two rectangle
        if(E>=C || F>=D || G<=A || H<=B)    return s; // no overlap
        return s - (min(C,G) - max(A,E)) * (min(D,H) - max(B,F)); //areas of the two rectangle - overlap
    }

  • 0
    W

    concise & straight,Thx for sharing.


Log in to reply
 

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