当前位置:网站首页>Mirror image of sword finger offer binary tree
Mirror image of sword finger offer binary tree
2022-06-24 23:34:00 【ciwei24456】
Title Description :
Operate a given binary tree , Transform it into a mirror image of the source binary tree .
such as :
Source binary tree 
Mirror binary tree 
Their thinking :
According to the definition of binary tree image , Consider recursive traversal (dfs) Binary tree , Swap the left side of each node / The right child node , The image of binary tree can be generated .
The problem solving steps :
1、 Special judgement : If pRoot It's empty , Returns an empty
2、 Exchange left and right subtrees
3、 hold pRoot Put the left subtree of Mirror Mirror in
4、 hold pRoot The right subtree of Mirror Mirror in
5、 Return root node root
Python Code implementation :
class Solution:
def Mirror(self , pRoot ):
# write code here
if not pRoot:
return pRoot
# Left and right subtrees exchange
pRoot.left, pRoot.right = pRoot.right, pRoot.left
# Recursive left and right subtrees
self.Mirror(pRoot.left)
self.Mirror(pRoot.right)
return pRoot
边栏推荐
- MySQL 表的增删查改
- libnum库简单使用(进制字符串转换)
- 去商场逛街
- 斐波那契
- 7-3 maximum sub segment and
- R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、通过双样本t检验分析(双独立样本t检验)来判断倾向性评分匹配后样本中的所有协变量的平衡情况
- 372. chessboard coverage
- The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and performs Welch double sample t-test analysis and double inde
- golang convert json string to map
- R语言使用epiDisplay包的aggregate函数将数值变量基于因子变量拆分为不同的子集,计算每个子集的汇总统计信息、自定义FUN参数为多个统计量函数名称的列表计算多个统计量
猜你喜欢

Ganglia 的安装与部署

7-7 digital triangle
![[JS] - [string - application] - learning notes](/img/dc/f35979b094f04c0ee13b3354c7741d.png)
[JS] - [string - application] - learning notes

Super detailed cookie addition, deletion, modification and query

基于三维GIS开发的水电工程建设方案

Tomorrow is the PMP Exam (June 25). Have you understood all this?

Understanding openstack network

InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog

企业数据防泄露解决方案分享

Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
随机推荐
[JS] - [tree] - learning notes
sql -CONVERT函数
7-3 最大子段和
RT thread uses RT kprintf
idea创建模块提示已存在
Morris traversal
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and performs Welch double sample t-test analysis and double inde
jar中没有主清单属性
No main manifest attribute in jar
HMS core discovery Episode 13 live broadcast Preview - building the real world in mobile games
golang convert map to json string
去处电脑桌面小箭头
Hydropower project construction scheme based on 3D GIS Development
7-8 circular scheduling problem
MySQL semi sync replication
明天就是PMP考试了(6月25日),这些大家都了解了吗?
无鸟用的SAP PA证书,刚入行的同行可以考一考
InnoDB, the storage engine of MySQL Architecture Principle_ Redo log and binlog
376. machine tasks
常用正则表达式