One line solution...


  • 0
    V
    public class Solution {
        public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
            return Math.abs((G-E)*(H-F))+Math.abs((D-B)*(C-A))-((C <= E || G <= A || H <= B || D <= F)?0:(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.