当前位置:网站首页>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;
}
}
边栏推荐
- Day5: PHP simple syntax and usage
- 110 MySQL interview questions and answers (continuously updated)
- Application scheme of charging pile
- LeetCode力扣题目总结(题目编号:53、3、141、面试题022、剑指offer链表中环的入口节点、20、19、牛客NC1、103、1143、牛客127)
- Squareline partners with visual GUI development of oneos graphical components
- Ar virtual augmentation and reality
- A little knowledge [synchronized]
- Hal library learning notes - 8 concept of serial communication
- 集群使用规范
- 数仓分层设计及数据同步问题,,220728,,,,
猜你喜欢

Solve the problem of MSVC2017 compiler with yellow exclamation mark in kits component of QT

User identity identification and account system practice

Chrony 时间同步

DAC0832 waveform generator based on 51 single chip microcomputer

Day15: the file contains the vulnerability range manual (self use file include range)

Common query optimization technology of data Lake - "deepnova developer community"

ROS common instructions

Is the sub database and sub table really suitable for your system? Talk about how to select sub databases, sub tables and newsql

Chrony time synchronization

Deep learning (1): prediction of bank customer loss
随机推荐
分段分页以及段页结合
Day15 (day16 extension): file contains vulnerability
Deep learning (1): prediction of bank customer loss
The first week of postgraduate freshman training: deep learning and pytorch Foundation
Multifunctional signal generator based on AD9850
User identity identification and account system practice
Virtual augmentation and reality Part 2 (I'm a Firebird)
Brief introduction and use of commonjs import and export and ES6 modules import and export
PostgreSQL manually creates hikaridatasource to solve the error cannot commit when autocommit is enabled
7.1-default-arguments
Osgsimplegl3 combined with renderdoc tool
Crawling JS encrypted data of playwright actual combat case
Four pin OLED display based on stm32
Clion+opencv+aruco+cmake configuration
Selenium actual combat case crawling JS encrypted data
Centos7/8 command line installation Oracle11g
深度学习(1):银行客户流失预测
access数据库可以被远程访问吗
Application of matrix transpose
Google browser cross domain configuration free