当前位置:网站首页>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
边栏推荐
- SimpleDateFormat 格式化和解析日期的具体类
- 376. machine tasks
- [JS] - [linked list - application] - learning notes
- R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用AIC函数比较两个模型的AIC值的差异(简单模型和复杂模型)
- 372. chessboard coverage
- R language uses the aggregate function of epidisplay package to split numerical variables into different subsets based on factor variables, calculate the summary statistics of each subset, and customi
- 257. 关押罪犯
- R language dplyr package group_ By function and summarize_ The at function calculates the dataframe to calculate the number of counts and the mean value of different groups (summary data by category v
- SQL -convert function
- 7-5 最大子矩阵和问题
猜你喜欢

单调栈以及单调栈的应用
![[JS] - [stack, team - application] - learning notes](/img/5b/b90ed8d3eb4fc0ab41c6ea8d092d0f.png)
[JS] - [stack, team - application] - learning notes

JS listens for page or element scroll events, scrolling to the bottom or top
What you must know about time series database!

Spark's wide dependence and narrow dependence yyds dry goods inventory

Yyds dry goods inventory tells us 16 common usage scenarios of redis at one go

斐波那契

First person singular reading notes

Installing IBM CPLEX academic edition | CONDA installing CPLEX

一文理解OpenStack网络
随机推荐
7-2 construction of binary tree by post order + middle order sequence
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用exp函数和coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比(odds ratio)
The dplyr package select function of R language moves the specified data column in the dataframe data to the first column (the first column) in the dataframe data column
Mousse shares listed on Shenzhen Stock Exchange: becoming popular by mattress and "foreign old man", with a market value of 22.4 billion yuan
R语言使用MASS包的polr函数构建有序多分类logistic回归模型、使用exp函数、confint函数、coef函数获取模型中每个变量(自变量改变一个单位)对应的优势比的置信区间
单调栈以及单调栈的应用
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
Ningde times will increase RMB 45billion: Hillhouse subscribes RMB 3billion and Zeng Yuqun still controls 23% of the equity
Continuous soul torture from two MySQL indexes of interviewers
斐波那契
The R language uses the matchit package for propensity matching analysis and match The data function constructs the matched sample set, and judges the balance of all covariates in the sample after the
R语言使用glm函数构建泊松对数线性回归模型处理三维列联表数据构建饱和模型、使用summary函数获取模型汇总统计信息、解读模型系数交互作用及其显著性
No main manifest attribute in jar
六大行数据治理现状盘点:治理架构、数据标准与数据中台(2022.04)
376. 機器任務
2021-2022中国金融数字化“新”洞察行业研究报告
Morris遍历
Morris traversal
7-2 求解买股票问题
7-6 laying oil well pipeline