当前位置:网站首页>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;
}
}
边栏推荐
- QT version of Snake game project
- Privacy is more secure in the era of digital RMB
- Squareline partners with visual GUI development of oneos graphical components
- LeetCode力扣题目总结(题目编号:53、3、141、面试题022、剑指offer链表中环的入口节点、20、19、牛客NC1、103、1143、牛客127)
- 数仓分层设计及数据同步问题,,220728,,,,
- User identity identification and account system practice
- 【Transformer】SegFormer:Simple and Efficient Design for Semantic Segmentation with Transformers
- [opencv] - Operator (Sobel, canny, Laplacian) learning
- (视频+图文)机器学习入门系列-第3章 逻辑回归
- Arfoundation starts from scratch 5-ar image tracking
猜你喜欢
Day15: the file contains the vulnerability range manual (self use file include range)
A little knowledge [synchronized]
The computer video pauses and resumes, and the sound suddenly becomes louder
Day13: file upload vulnerability
MySQL中的时间函数
WQS binary learning notes
RPC和REST
Proteus simulation based on msp430f2491 (realize water lamp)
Cluster usage specification
Solve the problem of MSVC2017 compiler with yellow exclamation mark in kits component of QT
随机推荐
Qpalette learning notes
Pnpm install appears: err_ PNPM_ PEER_ DEP_ ISSUES Unmet peer dependencies
[from_bilibili_dr_can][[advanced control theory] 9_ State observer design] [learning record]
Normal visualization
6.3 references
Analysis of zorder sampling partition process in Hudi - "deepnova developer community"
Hc-sr04 use method and routine of ultrasonic ranging module (STM32)
2022 Teddy cup data mining challenge C project and post game summary
pnpm install出现:ERR_PNPM_PEER_DEP_ISSUES Unmet peer dependencies
Collation of ml.net related resources
How to quickly experience oneos
Arfoundation starts from scratch 5-ar image tracking
Reading of false news detection papers (3): semi supervised content-based detection of misinformation via tensor embeddings
Day6: use PHP to write file upload page
Proteus simulation based on msp430f2491
Hal learning notes - Advanced timer of 7 timer
Unity shader learning (VI) achieving radar scanning effect
centos7/8命令行安装Oracle11g
Importerror: no module named XX
Intelligent shelf safety monitoring system