当前位置:网站首页>LeetCode652 寻找重复的子树
LeetCode652 寻找重复的子树
2022-07-21 10:36:00 【Coding~Man】
题目描述:给定一棵二叉树 root,返回所有重复的子树。对于同一类的重复子树,你只需要返回其中任意一棵的根结点即可。如果两棵树具有相同的结构和相同的结点值,则它们是重复的。
分析:要寻找重复的子树,我们可以首先获取每一个节点的子树,然后将这些子树进行对比判断,如果重复则加入链表中。如何判断两个子树的结构相等,可以引入map进行判断,先将一个子树的值存入map中,然后再分别将每一个子树存入map中,如果存入的时候发现以前存过,则将这个节点放入链表中,这样不断的循环。
知识点:hashmap相关知识
Map<String,Integer> count = new HashMap();
count.put(serial,count.getOrDefault(serial,0)+1);
count.get(serial) == 2;
链表知识点
List<TreeNode> ans;
边栏推荐
- 《穷查理宝典》感悟
- Array / slice of go
- Cloud native sig live broadcast: About CNI and hybridnet core technology sharing | issue 35
- Single example of game code specification
- Data too long for column ‘......‘ at row 2
- Deque容器的系列操作( 详解 )
- DAY 5 (数组)
- 打造一个生命周期感知的MVP架构
- Brief analysis of Redux technology stack (2): understanding saga's buffer and Chanel
- 如何选择加壳工具?
猜你喜欢
随机推荐
filebeat自动关闭解决
Deque容器的系列操作( 详解 )
《如果……》拉迪亚德·吉卜林
Matplotlib (VI) 3D mapping
jdbc 09: preparedStatement实现增删改查
剑指 Offer 45. 把数组排成最小的数
简易shader实践记录4-流光效果
百度地图、高德地图、腾讯地图三位一体地图定位开发
怎样才能让需求无法如期顺利上线(五)业务验收阶段
Tensorflow serving deployment tensorflow, keras model details
极化SAR——极化椭圆
Solution to the offset of Gaode map positioning on GeoServer layer
MUMU模拟器通过monitor查看日志输出
unity-表面着色器基础备忘录
Use okgo to update, download and install the software version
我的创作纪念日
day 4 (项目一:家庭收支记录)
Discussion on the practice of layaair
GBDT框架
同一个Activity中不同Fragment的数据传递