File tree
Expand file treeCollapse file tree1 file changed
+15
-0
lines changed Expand file treeCollapse file tree1 file changed
+15
-0
lines changed Original file line number | Diff line number | Diff line change |
---|
@@ -148,5 +148,20 @@ private boolean allSame(Node n) {
|
148 | 148 | (n.topLeft.val && n.bottomLeft.val);
|
149 | 149 | }
|
150 | 150 |
|
| 151 | + |
| 152 | +public Node intersect2(Node q1, Node q2) { |
| 153 | +if (q1.isLeaf) return q1.val ? q1 : q2; |
| 154 | +if (q2.isLeaf) return q2.val ? q2 : q1; |
| 155 | +q1.topLeft = intersect(q1.topLeft, q2.topLeft); |
| 156 | +q1.topRight = intersect(q1.topRight, q2.topRight); |
| 157 | +q1.bottomLeft = intersect(q1.bottomLeft, q2.bottomLeft); |
| 158 | +q1.bottomRight = intersect(q1.bottomRight, q2.bottomRight); |
| 159 | +if (allLeaves(q1) && allSame(q1)) { |
| 160 | +q1.isLeaf = true; |
| 161 | +q1.val = q1.topLeft.val; |
| 162 | +} |
| 163 | +return q1; |
| 164 | +} |
| 165 | + |
151 | 166 | }
|
152 | 167 |
|
You can’t perform that action at this time.
0 commit comments