My short java clean solution

  • 0
    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
            int res = calculate(A,B,C,D) + calculate(E,F,G,H);
            return res - calculate(Math.max(A,E),Math.max(B,F),Math.min(C,G),Math.min(D,H));
        private int calculate(int a,int b,int c,int d) {
            if(a >= c || b >= d) return 0;
            return (c - a) * (d - b);

Log in to reply

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