Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane.

Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.

Assume that the total area is never beyond the maximum possible value of int.

Code

public class Solution {
    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int common;
        if (E>=C || A>=G || B>=H || F>=D) {common=0;}
        else {
            int width = Math.min(G, C) - Math.max(A,E);
            int height = Math.min(D, H) - Math.max(B,F);
            common = width*height;
        }
        return (C-A)*(D-B)+(G-E)*(H-F)-common;
    }
}