package leetcode;

/**
 * https://leetcode.com/problems/rectangle-overlap/
 */
public class Problem836 {
    public boolean isRectangleOverlap(int[] rec1, int[] rec2) {
        return (rec1[0] < rec2[0] && rec2[0] < rec1[2] ||
                rec1[0] < rec2[2] && rec2[2] < rec1[2]) &&
               (rec1[1] < rec2[1] && rec2[1] < rec2[3] ||
                rec1[1] < rec2[3] && rec2[3] < rec2[3]);
    }

    public static void main(String[] args) {
        Problem836 prob = new Problem836();
        System.out.println(prob.isRectangleOverlap(new int[]{0, 0, 2, 2}, new int[]{1, 1, 3, 3})); // true
        System.out.println(prob.isRectangleOverlap(new int[]{0, 0, 1, 1}, new int[]{1, 0, 2, 1})); // false
        System.out.println(prob.isRectangleOverlap(new int[]{0, 0, 1, 1}, new int[]{0, 0, 2, 1})); // false
        System.out.println(prob.isRectangleOverlap(new int[]{0, 0, 2, 2}, new int[]{0, 1, 1, 1})); // false
        System.out.println(prob.isRectangleOverlap(new int[]{7, 8, 13, 15}, new int[]{10, 8, 12, 20})); // true
    }
}

@@ -174,16 +174,41 @@
     
-return (
+boolean xIntersect =%0A            
 rec1
@@ -249,36 +249,32 @@
  %7C%7C%0A            
-    
 rec1%5B0%5D %3C rec2%5B2
@@ -299,14 +299,12 @@
 1%5B2%5D
-) &&%0A 
+ %7C%7C%0A
     
@@ -315,35 +315,32 @@
     
-  (rec1%5B1
+rec2%5B0
 %5D %3C rec
-2%5B1
+1%5B0
 %5D && rec
 2%5B1%5D
@@ -339,11 +339,11 @@
  rec
-2%5B1
+1%5B0
 %5D %3C 
@@ -347,17 +347,17 @@
  %3C rec2%5B
-3
+2
 %5D %7C%7C%0A   
@@ -369,36 +369,32 @@
     
-    rec1%5B1
+rec2%5B0
 %5D %3C rec
-2%5B3
+1%5B2
 %5D && rec
 2%5B3%5D
@@ -389,19 +389,19 @@
 %5D && rec
-2%5B3
+1%5B2
 %5D %3C rec2
@@ -405,651 +405,295 @@
 ec2%5B
-3%5D)
+2%5D
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem836 prob = new Problem836();%0A        System.out.println(prob.isRectangleOverlap(new int%5B%5D%7B0, 0, 2, 2%7D, new int%5B%5D%7B1, 1, 3, 3%7D)); // true%0A        System.out.println(prob.isRectangleOverlap(new int%5B%5D%7B0, 0, 1, 1%7D, new int%5B%5D%7B1, 0, 2, 1%7D)); // false%0A        System.out.println(prob.isRectangleOverlap(new int%5B%5D%7B0, 0, 1, 1%7D, new int%5B%5D%7B0, 0, 2, 1%7D)); // false%0A        System.out.println(prob.isRectangleOverlap(new int%5B%5D%7B0, 0, 2, 2%7D, new int%5B%5D%7B0, 1, 1, 1%7D)); // false%0A        System.out.println(prob.isRectangleOverlap(new int%5B%5D%7B7, 8, 13, 15%7D, new int%5B%5D%7B10, 8, 12, 20%7D)); // true
+boolean yIntersect =%0A            rec1%5B1%5D %3C rec2%5B1%5D && rec2%5B1%5D %3C rec1%5B3%5D %7C%7C%0A            rec1%5B1%5D %3C rec2%5B3%5D && rec2%5B3%5D %3C rec1%5B3%5D %7C%7C%0A            rec2%5B1%5D %3C rec1%5B1%5D && rec1%5B1%5D %3C rec2%5B3%5D %7C%7C%0A            rec2%5B1%5D %3C rec1%5B3%5D && rec1%5B3%5D %3C rec2%5B3%5D;%0A        return xIntersect && yIntersect;
 %0A   

Solve problem 836