当前位置:网站首页>Mirror image of binary tree
Mirror image of binary tree
2022-06-25 05:21:00 【Don't hit me, it hurts!】
subject

[ Simple 、 recursive ]
Answer key
The left and right subtrees of a commutative binary tree
function Mirror( pRoot ) {
// Recursive export
if(pRoot === null){
return pRoot;
} else {
[pRoot.left,pRoot.right] = [pRoot.right,pRoot.left]
}
Mirror(pRoot.left);
Mirror(pRoot.right);
return pRoot;
}
Supplementary knowledge
Answer template of binary tree
function traverse(TreeNode root){
// The former sequence traversal
traverse(root.left)
// In the sequence traversal
traverse(root.right)
// After the sequence traversal
}
The central idea of recursion :
- Consider exporting ( if part )
- Process the current node
- Recursively process the next node
Recursive exit of binary tree problem , Generally include :
// 1. Node is empty ( To the leaf node )
pRoot === null
The article links : Image of binary tree [ The finger of the sword offer]
* Please quote from QW’s Blog!*
边栏推荐
- Understand JS high-order function and write a high-order function
- Large number operation (capable of square root, power, permutation and combination, logarithm and trigonometric value)
- Personalized Federated Learning with Moreau Envelopes
- Database query optimization method
- SSRF-lab
- MySQL prevents Chinese garbled code and solves the problem of Chinese garbled code
- The print area becomes smaller after epplus copies the template
- 1.5.3 use tcpdump to observe ARP communication process
- Enhanced paste quill editor
- [Huawei machine test] hj16 shopping list
猜你喜欢

What is Ethernet and how to connect the computer

JSON Library Tutorial from scratch (II): parsing digital learning and sorting notes

ThinkPHP 5 log management

Penetration test - right raising topic

How to install the blue lake plug-in to support Photoshop CC 2017

Deep analysis of recursion in quick sorting

February 20ctf record

渗透测试-提权专题

JSON Library Tutorial from scratch (III): parsing strings, learning and sorting notes

Svg code snippet of loading animation
随机推荐
Install pytorch through pip to solve the problem that torch cannot be used in jupyter notebook (modulenotfoundererror:no module named 'Torch').
Penetration test - right raising topic
SRC platform summary
Keyboard key code value
Dynamic programming full backpack
API interface management setup -eolinker4.0
How micro engine uploads remote attachments
February 20ctf record
2021-03-23
JS handwriting depth clone array and object
C style string
Laravel's little knowledge
There is 404 in the laravel visit, except the home page is redirected; Index php
First blog
2022.1.21 diary
Duplicate symbols for architecture i386 clang
Read the general components of antd source code
How to install the blue lake plug-in to support Photoshop CC 2017
投资理财产品的年限要如何选?
Detailed summary of float