当前位置:网站首页>ByteDance Interview Questions: Mirror Binary Tree 2020
ByteDance Interview Questions: Mirror Binary Tree 2020
2022-08-09 06:32:00 【In the history of the strongest disciple】
Please complete a function that takes as input a binary tree and the function outputs its mirror image.
For example enter:
4
/ / \
2 7
/ \ / \
1 3 6 9
Mirror output:
4
/ / \
7 2
/ \ / \
9 6 3 1
Example:
Input: root = [4,2,7,1,3,6,9]Output: [4,7,2,9,6,3,1]
The idea of solving the problem is the breadth-first traversal of the tree. There is also a data exchange problem, which is an extension of the data exchange problem of array data blocks. If you are interested, you can go to see Zuo Shen's A B A BA exchange problem.
import java.util.ArrayList;import java.util.List;public class test7 {public TreeNode mirrorTree(TreeNode root) {if(root == null){return root;}List list = new ArrayList<>();list.add(root);while (list.size()>0){List newList = new ArrayList<>();for(int i = 0;i
Output result:
边栏推荐
猜你喜欢
C language implements sequential stack and chain queue
C# 利用iTextSharp画PDF
mongo+ycsb性能测试及线程数分析
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
Gao Zelong, a famous digital collection expert and founder of the Digital Collection Conference, was interviewed by China Entrepreneur Magazine
[GO], arrays and slices
字节跳动笔试题2020 (抖音电商)
6 states of a thread
中英文说明书丨CalBioreagents 醛固酮单克隆抗体
C语言的内置宏(定义日志宏)
随机推荐
Likou Brush Question 180
分布式id 生成器实现
crc calculation
Excel受保护的工作表怎么操作?
vs番茄助手的方便功能和便捷快捷键介绍
如何操作数据库
直接用的zip包 缺少很多依赖,pip没有,感觉用anaconda create一个环境会方便点
Qt 学习(三) —— Qt 模块
深度学习-神经网络原理2
Inception V3 闭眼检测
shardingsphere数据分片配置项说明和示例
P7阿里面试题2020.07 之滑动窗算法(阿里云面试)
详解C语言中的wait()函数和waitpid()函数
VB.net程序关闭后后台还在与SQL连接
Ferric oxide/bismuth sulfide nanocomposites ([email protected]@BSABiS nanoparticles) | dendrimer-stabilized bismuth sulfide nanop
2022-08-08: Given an array arr, it represents the height of the missiles that will appear in order from morning to night.When the cannon shoots missiles, once the cannon is set to shoot at a certain h
APP商品详情源数据接口(淘宝/京东/拼多多/苏宁/抖音等平台详情数据分析接口)代码对接教程
sql问题解答创建表的语句
SIGINT,SIGKILL,SIGTERM信号区别,各类信号总结
什么是excel文件保护