Share my three line c++ solution


  • 1
    L
    class Solution {
    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) + (G-E)*(H-F);
            
            if (A>G || E>C || B>H || F>D) return area; //no overlap
            return area-(min(C,G)-max(A,E))*(min(D,H)-max(B,F));
        }
    };

Log in to reply
 

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