My simple Java solution


  • 1
    E
    public class Solution {
        public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
            int a1 = Math.abs((C-A)*(D-B));
            int a2 = Math.abs((G-E)*(H-F));
            if(E>=C||G<=A||D<=F||B>=H) return a1+a2;
            else return a1+a2-(Math.min(C,G)-Math.max(A,E))*(Math.min(D,H)-Math.max(B,F));
        }
    }
    

Log in to reply
 

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