package com.fishercoder.solutions;

/**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.

 Rectangle Area
 Assume that the total area is never beyond the maximum possible value of int.*/
public class _223 {

    public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {
        int areaA = (C - A) * (D - B);
        int areaB = (G - E) * (H - F);

        int top = Math.min(D, H);
        int bottom = Math.max(B, F);
        int left = Math.max(A, E);
        int right = Math.min(C, G);

        int overlap = 0;
        if (top > bottom && right > left) {
            overlap = (top - bottom) * (right - left);
        }
        return areaA + areaB - overlap;
    }

}

@@ -32,16 +32,46 @@
 ns;%0A%0A/**
+%0A * 223. Rectangle Area%0A *%0A * 
 Find the
@@ -135,17 +135,18 @@
  plane.%0A
-%0A
+ *
  Each re
@@ -235,17 +235,18 @@
 figure.%0A
-%0A
+ *
  Rectang
@@ -253,16 +253,112 @@
 le Area%0A
+%0A Example:%0A%0A Input: A = -3, B = 0, C = 3, D = 4, E = 0, F = -1, G = 9, H = 2%0A Output: 45%0A%0A Note:
  Assume 
@@ -451,16 +451,56 @@
 _223 %7B%0A%0A
+    public static class Solution1 %7B%0A    
     publ
@@ -572,24 +572,28 @@
 G, int H) %7B%0A
+    
         int 
@@ -619,32 +619,36 @@
 D - B);%0A        
+    
 int areaB = (G -
@@ -667,24 +667,28 @@
 );%0A%0A        
+   
+ 
 int top = Ma
@@ -701,16 +701,20 @@
 (D, H);%0A
+    
         
@@ -746,24 +746,28 @@
 F);%0A        
+  
+  
 int left = M
@@ -781,16 +781,20 @@
 (A, E);%0A
+    
         
@@ -826,24 +826,28 @@
 );%0A%0A        
+ 
+   
 int overlap 
@@ -851,16 +851,20 @@
 ap = 0;%0A
+    
         
@@ -911,16 +911,20 @@
         
+    
 overlap 
@@ -966,18 +966,26 @@
         
+   
+ 
 %7D%0A
+    
         
@@ -1020,13 +1020,22 @@
 ap;%0A    
+    %7D%0A    
 %7D
-%0A
 %0A%7D%0A

refactor 223