当前位置:网站首页>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
边栏推荐
- 7-5 maximal submatrix sum problem
- HarmonyOS访问数据库实例(3)--用ORM Bee测下HarmonyOS到底有多牛
- What good smart home brands in China support homekit?
- #22Map介绍与API
- UNION ALL UNION FULL JOIN
- Common regular expressions
- R语言使用MatchIt包进行倾向性匹配分析、使用match.data函数构建匹配后的样本集合、通过双样本t检验分析(双独立样本t检验)来判断倾向性评分匹配后样本中的所有协变量的平衡情况
- R language uses GLM function to build Poisson log linear regression model, processes three-dimensional contingency table data to build saturation model, uses summary function to obtain model summary s
- R语言dplyr包group_by函数和summarise_at函数计算dataframe计算不同分组的计数个数和均值(Summarise Data by Categorical Variable)
- 【UVM入门 ===> Episode_8 】~ Sequence 和 Sequencer、Sequence 层次化
猜你喜欢
HMS core discovery Episode 13 live broadcast Preview - building the real world in mobile games
![[JS] - [array application] - learning notes](/img/8a/808fde0cc86e0ec5e1f5558ba196b4.png)
[JS] - [array application] - learning notes

中学校园IP网络广播系统解决方案-校园数字IP广播系统方案设计指南
What you must know about time series database!

Understanding openstack network

Ganglia 的安装与部署

js监听页面或元素scroll事件,滚动到底部或顶部
![[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy](/img/d0/7d78b00e4f6ad1e8efb73a5d472b09.png)
[introduction to UVM== > episode_8] ~ sequence and sequencer, sequence hierarchy

Morris遍历

【js】-【數組、棧、隊列、鏈錶基礎】-筆記
随机推荐
#22Map介绍与API
golang map clear
点的螺旋距离
UNION ALL UNION FULL JOIN
单调栈以及单调栈的应用
sql -CONVERT函数
Tomorrow is the PMP Exam (June 25). Have you understood all this?
R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用summary函数获取模型汇总统计信息、解读模型系数交互作用及其显著性
JS listens for page or element scroll events, scrolling to the bottom or top
Websocket long link pressure test
Use of types, values, namespaces, combinations, etc. in typescript
Inventory of data governance status of six major banks: governance architecture, data standards and data middle office (April 2022)
常用正则表达式
372. 棋盘覆盖
Annual salary of millions, 7 years of testing experience: stay at a fairly good track, accumulate slowly, wait for the wind to come
当初吃土建起来的“中台”,现在为啥不香了?
HMS core discovery Episode 13 live broadcast Preview - building the real world in mobile games
2021-2022中国金融数字化“新”洞察行业研究报告
R language uses GLM function to build Poisson log linear regression model, processes three-dimensional contingency table data to build saturation model, uses summary function to obtain model summary s
7-7 求解众数问题