AC java 5ms Silly approach [with comments]


  • 0
    M
    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
    int a1 = Math.abs((C - A) * (D - B));
    int a2 = Math.abs((G - E) * (H - F));
    boolean intersect = Math.max(A, E) < Math.min(G, C) && Math.max(B, F) < Math.min(D, H);
    int overlap = Math.abs((Math.min(G, C) - Math.max(A, E)) * (Math.min(D, H) - Math.max(B, F)));
    // !empty area && intersect
    return a1 + a2 - ((a1 != 0 && a2 != 0 && intersect) ? overlap : 0);
    
    }

Log in to reply
 

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