java solution with non-interact judgement


  • 0
    M

    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
    // find no interact situations : top-botton or left-right
    // first step to define the non-interact between two rectangle condition
    // second to calcu interact area
    // finally sum both area minus one interact area
    int common = 0;
    if(B>=H || F>=D || C<=E || G<=A) {
    common = 0;
    } else {
    common = (Math.min(D, H) - Math.max(B, F)) * (Math.min(C, G) - Math.max(A, E));
    }
    return (C-A)(D-B) + (G-E)(H-F) - common;
    }


Log in to reply
 

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