Very easy java solution - less than 10 lines


  • 0
    V
    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int area = (C - A) * (D - B) + (H - F) * (G - E);
        //No overlap
        if (A >= G || C <= E || B >= H || D <= F) return area;
        //Overlap
        int overlap_area = (Math.min(C, G) - Math.max(A, E)) * (Math.min(D, H) - Math.max(F, B));
        return area - overlap_area;
    }

Log in to reply
 

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