/*
// Definition for a QuadTree node.
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;
}
};
*/
class Solution {
public Node intersect(Node quadTree1, Node quadTree2) {
if (quadTree1.isLeaf){
// 是否是叶子节点,是的话就返回node1,否则就是node2
return quadTree1.val ? new Node(true, true, null, null, null, null) : quadTree2;
}
if (quadTree2.isLeaf){
return quadTree2.val ? new Node(true, true, null, null, null, null) : quadTree1;
}
Node tl = intersect(quadTree1.topLeft, quadTree2.topLeft), tr = intersect(quadTree1.topRight, quadTree2.topRight),
bl = intersect(quadTree1.bottomLeft, quadTree2.bottomLeft), br = intersect(quadTree1.bottomRight, quadTree2.bottomRight);
return tl.isLeaf && tr.isLeaf && bl.isLeaf && br.isLeaf && tl.val == tr.val && tl.val
== bl.val && tl.val == br.val ?
new Node(tl.val, true, null, null, null, null) :
new Node(false, false, tl, tr, bl, br);
}
}
没看懂题目,所以直接CV了