A 20ms C solution


  • 1
    G
    int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int areaA = (C - A)*(D - B);
        int areaB = (G - E)*(H - F);
        
        if (C <= E || A >= G || B >= H || D <= F) {
            return areaA + areaB;
        }
        
        int rightX = (E <= C && C <= G) ? C : G;
        int leftX = (E >= A && E <= rightX) ? E : A;
        
        int topY = (H <= D && H >= B) ? H : D;
        int botY = (B >= F && B <= topY) ? B : F;
        
        return areaA + areaB - (topY - botY)*(rightX - leftX);
    }

Log in to reply
 

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