// Definition for a QuadTree node.
Node(bool _val, bool _isLeaf, Node* _topLeft, Node* _topRight, Node* _bottomLeft, Node* _bottomRight) {
bottomLeft = _bottomLeft;
bottomRight = _bottomRight;
Node* intersect(Node* quadTree1, Node* quadTree2) {
if(quadTree1->isLeaf) return quadTree1->val ? quadTree1 : quadTree2;
if(quadTree2->isLeaf) return quadTree2->val ? quadTree2 : quadTree1;
Node* topL = intersect(quadTree1->topLeft, quadTree2->topLeft);
Node* topR = intersect(quadTree1->topRight, quadTree2->topRight) ;
Node* bottomL = intersect(quadTree1->bottomLeft, quadTree2->bottomLeft);
Node* bottomR = intersect(quadTree1->bottomRight, quadTree2->bottomRight) ;
if(topL->isLeaf && topR->isLeaf && bottomL->isLeaf && bottomR->isLeaf && topL->val == topR->val && topL->val ==bottomL->val && topL->val == bottomR->val ) return new Node(topL->val , true, NULL, NULL, NULL,NULL);
return new Node(false, false, topL, topR, bottomL, bottomR);