当前位置:网站首页>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);
}
}
边栏推荐
- vSphere 下借助 vDS 或 NSX 做端口镜像的方法总结
- [handwritten numeral recognition] handwritten numeral recognition based on lenet network with matlab code
- 剑指 Offer II 041. 滑动窗口的平均值
- Tencent cloud server uses image to deploy WordPress personal website!
- Nombre d'entrées nombre d'entrées numériques pures limite de longueur maximale
- ROS duplicate name
- Data Guard Broker的概念和Data Guard Broker的配置过程
- antd 下拉多选传值到后台做查询操作
- Category imbalance in classification tasks
- Introduction to the universal theme system of SAP appgyver
猜你喜欢

Unity Dropdown(可编辑,可输入)下拉选择框,带文本联想

Beego framework realizes file upload + seven cattle cloud storage

英伟达用AI设计GPU:最新H100已经用上,比传统EDA减少25%芯片面积

Documents required for military product development process - advanced version

Journal日志与oplog日志的区别

Opencv programming: opencv3 X trains its own classifier

数据库锁的介绍与InnoDB共享,排他锁

常用getshell工具的下载

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

How to build dashboard and knowledge base in double chain note taking software? Take the embedded widget library notionpet as an example
随机推荐
LeetCode 2335. Minimum total time required to fill the cup
6G全域融合网络展望
博弈论(depu)与投资(40/100)
To get to the bottom: Principle Analysis of Objective-C correlation attribute
The concept of data guard broker and the configuration process of data guard broker
今日睡眠质量记录79分
Win10 start key click no response
PowerCLI 脚本性能优化
Goldfish rhca memoirs: cl210 describes the openstack control plane -- identify the overcloud control platform service + chapter experiment
Scala's dosing in idea
人大、微软等提出InclusiveFL:异构设备上的包容性联邦学习
Huawei machine test: number of continuous licensing
leetcode-08
[PostgreSQL] PostgreSQL 15 optimizes distinct
Google Earth Engine——Hansen Global Forest Change v1.8 (2000-2020) 森林覆盖度和森林损失量数据集
Mysql优化系列之limit查询
6G中的卫星通信高效天基计算技术
剑指 Offer II 041. 滑动窗口的平均值
UE4 understanding of animation blueprint
vulnhub inclusiveness: 1