A straight forward C++ solution ..

  • 0

    this one work ok and accpetecd. Still look straight forward.

    class Solution {
        int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
            if(A>=G||B>=H||C<=E||D<=F)   // no overlap
                return (C-A)*(D-B)+(G-E)*(H-F);
            else                         // otherwise overlap
                return (C-A)*(D-B)+(G-E)*(H-F)-(min(C,G)-max(A,E))*(min(D,H)-max(B,F)); // minus overlap area
    };  //2016 06 12 凌晨

Log in to reply

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