package leetcode;

/**
 * https://leetcode.com/problems/quad-tree-intersection/
 */
public class Problem558 {
    private static class Node {
        public boolean val;
        public boolean isLeaf;
        public Node topLeft;
        public Node topRight;
        public Node bottomLeft;
        public Node bottomRight;

        public Node() {
        }

        public Node(boolean _val,
                    boolean _isLeaf,
                    Node _topLeft,
                    Node _topRight,
                    Node _bottomLeft,
                    Node _bottomRight) {
            val = _val;
            isLeaf = _isLeaf;
            topLeft = _topLeft;
            topRight = _topRight;
            bottomLeft = _bottomLeft;
            bottomRight = _bottomRight;
        }
    }

    public Node intersect(Node quadTree1, Node quadTree2) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem558 prob = new Problem558();
    }
}

@@ -862,35 +862,954 @@
     
-// TODO%0A        return null
+if (quadTree1.isLeaf && quadTree2.isLeaf) %7B%0A            Node topLeft = intersect(quadTree1.topLeft, quadTree2.topLeft);%0A            Node topRight = intersect(quadTree1.topRight, quadTree2.topRight);%0A            Node bottomLeft = intersect(quadTree1.bottomLeft, quadTree2.bottomLeft);%0A            Node bottomRight = intersect(quadTree1.bottomRight, quadTree2.bottomRight);%0A            return new Node(false, true, topLeft, topRight, bottomLeft, bottomRight);%0A        %7D else if (!quadTree1.isLeaf) %7B%0A            boolean val = quadTree1.topLeft.val %7C quadTree1.topRight.val %7C%0A                quadTree1.bottomLeft.val %7C quadTree1.bottomRight.val;%0A            return new Node(val %7C quadTree2.val, false, null, null, null, null);%0A        %7D%0A        boolean val = quadTree2.topLeft.val %7C quadTree2.topRight.val %7C%0A            quadTree2.bottomLeft.val %7C quadTree2.bottomRight.val;%0A        return new Node(quadTree1.val %7C val, false, null, null, null, null)
 ;%0A  

Update problem 558