simple c++ solution, 84.74%


  • 2
    M
    class Solution {
    public:
        int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
            int nblx = (A > E) ? A : E;
            int nbly = (B > F) ? B : F;
            int ntrx = (C > G) ? G : C;
            int ntry = (D > H) ? H : D;
            int uni = 0;
            if (ntrx >= nblx && ntry >= nbly) uni = (ntrx - nblx) * (ntry - nbly);
            return ((C - A) * (D - B) + (G - E) * (H - F)) - uni;
        }
    };
    

Log in to reply
 

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