当前位置:网站首页>Sword finger offer 27. image of binary tree
Sword finger offer 27. image of binary tree
2022-07-29 08:35:00 【ThE wAlkIng D】
Title Description

Problem analysis
Ontology uses queues to do , The purpose of the queue is to store the binary tree of the original sequence order
First, determine whether the root node is empty
Then create a new sub queue
The queue is pushed into the root node
Use while( loop )
Pop up queue elements
Press in the left and right nodes respectively
Switch left and right nodes
Return to the initial node
Code instance
class Solution {
public TreeNode mirrorTree(TreeNode pRoot) {
if(pRoot == null){
return null;
}
Queue<TreeNode> que = new LinkedList<>();
que.offer(pRoot);
while(!que.isEmpty()){
TreeNode temp = que.poll();
if(temp.left != null){
que.offer(temp.left);
}
if(temp.right != null){
que.offer(temp.right);
}
TreeNode tem = temp.left;
temp.left = temp.right;
temp.right = tem;
}
return pRoot;
}
}
边栏推荐
- Fastjson's tojsonstring() source code analysis for special processing of time classes - "deepnova developer community"
- Requests library simple method usage notes
- 2022 Teddy cup data mining challenge C project and post game summary
- Use SQL client How can the job generated by SH achieve breakpoint continuation after cancle?
- Collation of ml.net related resources
- Hal library learning notes - 8 concept of serial communication
- Multifunctional signal generator based on AD9850
- Txt plain text operation
- What is the working principle of the noise sensor?
- Inclination monitoring solution of Internet of things
猜你喜欢

Centos7/8 command line installation Oracle11g

Stm8s003 domestic substitute for dp32g003 32-bit microcontroller chip

集群使用规范

Intelligent shelf safety monitoring system

Time function in MySQL

ADB common command list

Google browser cross domain configuration free

Lesson 3 threejs panoramic preview room case

Second week of postgraduate freshman training: convolutional neural network foundation

7.2-function-overloading
随机推荐
Second week of postgraduate freshman training: convolutional neural network foundation
ML.NET相关资源整理
Proteus simulation based on msp430f2491 (realize water lamp)
Is the sub database and sub table really suitable for your system? Talk about how to select sub databases, sub tables and newsql
What if official account does not support markdown format file preparation?
What is the working principle of the noise sensor?
(视频+图文)机器学习入门系列-第3章 逻辑回归
Reading papers on false news detection (4): a novel self-learning semi supervised deep learning network to detect fake news on
Centos7/8 command line installation Oracle11g
Tensorboard use
Day5: PHP simple syntax and usage
Unity shader learning (VI) achieving radar scanning effect
Application scheme of charging pile
Intelligent temperature control system
Day15: the file contains the vulnerability range manual (self use file include range)
User identity identification and account system practice
GBase 8s数据库有哪些备份恢复方式
Clickhouse learning (I) Clickhouse?
Basic shell operations (Part 2)
MySQL中的时间函数