I used abs value, and borrowed technique from another solution that worked


  • 2
    T
    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        
        int space =0;
        int space1 = (Math.abs(A-C)*Math.abs(B-D));
        int space2 =(Math.abs(E-G)*Math.abs(F-H));
        
        //borrowed from anther solution
        int left = Math.max(A,E);
        int right = Math.min(G,C);
        int top = Math.min(D,H);
        int bottom = Math.max(B,F);
        
        if (top >= bottom && right >= left) {
            space = (Math.abs(bottom-top)*Math.abs(left-right));
        }
        return space1+space2-space;
        
    }

Log in to reply
 

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