当前位置:网站首页>LeetCode 558. Intersection of quadtree
LeetCode 558. Intersection of quadtree
2022-07-19 11:08:00 【Sasakihaise_】
558. The intersection of quadtrees




【 Divide and conquer + recursive 】 This question is too long , But we can simply sort it out :
1. If either of the two nodes is a leaf :
If the leaf is 1, Then directly return to 1 Just leave it
If the leaf is 0, Then directly return to another node
2. Recursive processing of four children , Get four recursive results respectively
If all four are leaves ,
If it's all 1, Returns a merged large 1 node
If it's all 0, Returns a merged large 0 node
otherwise , Return to create a large node based on four recursive nodes
/*
// 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 {
// 4.12 16
public Node dfs(Node n1, Node n2) {
Node node = new Node();
if (n1.isLeaf) {
if (n1.val == true) return new Node(true, true, null, null, null, null);
else return n2;
}
if (n2.isLeaf) {
if (n2.val == true) return new Node(true, true, null, null, null, null);
else return n1;
}
Node tl = dfs(n1.topLeft, n2.topLeft);
Node tr = dfs(n1.topRight, n2.topRight);
Node bl = dfs(n1.bottomLeft, n2.bottomLeft);
Node br = dfs(n1.bottomRight, n2.bottomRight);
if (tl.isLeaf && tr.isLeaf && bl.isLeaf && br.isLeaf) {
if (tl.val && tr.val && bl.val && br.val) {
return new Node(true, true, null, null, null, null);
}
if (tl.val == false && tr.val == false && bl.val == false && br.val == false) {
return new Node(false, true, null, null, null, null);
}
}
return new Node(false, false, tl, tr, bl, br);
}
public Node intersect(Node quadTree1, Node quadTree2) {
return dfs(quadTree1, quadTree2);
}
}
边栏推荐
- NVIDIA uses AI to design GPU: the latest H100 has been used, which reduces the chip area by 25% compared with traditional EDA
- Use and principle of ThreadLocal variable
- IP SAN has an independent file system. After the application server accesses the IP SAN through the network sharing protocol, it can read and write the files in the file system
- Detailed explanation of multiple linear regression
- 2022/7/16
- Detailed explanation of Euler angle, axis angle, quaternion and rotation matrix
- Beego framework realizes file upload + seven cattle cloud storage
- Second classification learning is extended to multi classification learning
- E-commerce sales data analysis and prediction (date data statistics, daily statistics, monthly statistics)
- Getting started with web security - deploy snort open source ids/ips system
猜你喜欢

UE4 understanding of animation blueprint
![Some methods of early MCU encryption [get data in the comment area]](/img/14/8e1dcb799d8a3c0aefcac09be9dc51.png)
Some methods of early MCU encryption [get data in the comment area]

NVIDIA uses AI to design GPU: the latest H100 has been used, which reduces the chip area by 25% compared with traditional EDA

ThreadLocal变量使用及原理

Daily question brushing record (26)
![[handwritten numeral recognition] handwritten numeral recognition based on lenet network with matlab code](/img/17/97b46355dbfa02608af2f91d7d6409.png)
[handwritten numeral recognition] handwritten numeral recognition based on lenet network with matlab code

每日刷题记录 (二十六)

ROS duplicate name

Second classification learning is extended to multi classification learning

LeetCode 2319. Judge whether the matrix is an X matrix
随机推荐
Opencv programming: opencv3 X trains its own classifier
腾讯云服务器利用镜像部署WordPress个人网站!
QT two overloaded qlistwidget control objects implement selectitem drag drag
Pytoch framework learning record 1 cifar-10 classification
空天地海一体化网络体系架构与网络切片技术
Win10 install Apache Jena 3.17
Integrated network architecture and network slicing technology of air, earth and sea
2022/7/15
Scala在Idea中的配量
Efficient space-based computing technology for satellite communication in 6g
Win10安装Apache Jena 3.17
人大、微软等提出InclusiveFL:异构设备上的包容性联邦学习
Introduction to virtualization troubleshooting
Future applications and technical challenges of backscatter communication
Develop the first Flink app
Rotation in unity3d
LeetCode 2335. Minimum total time required to fill the cup
ROS duplicate name
Use and principle of ThreadLocal variable
Today's sleep quality record 79 points