Another Java AC Short and Straightforward Solution


  • 0
    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int height = (int) Math.max(0, (long) Math.min(D, H) - (long) Math.max(B, F));
        int width = (int) Math.max(0, (long) Math.min(C, G) - (long) Math.max(A, E));
        int overlap =  height * width;
        return (D - B) * (C - A) + (H - F) * (G - E) - overlap;
    }

Log in to reply
 

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