My simple java accepted 10 line code


  • 0
    D
    public class Solution {
        public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
            int left = Math.max(A,E);
            int right = Math.min(C,G);
            int bottom = Math.max(B,F);
            int top = Math.min(D,H);
            int commonArea = 0;
            if(left < right && bottom < top) {
                commonArea = (right-left) * (top-bottom);
            }
            return ( (C-A) * (D-B)) + ((G-E) * (H-F)) - commonArea;
        }
    }

Log in to reply
 

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