当前位置:网站首页>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:

边栏推荐
- 2022.8.8DAY628
- Ferric oxide/bismuth sulfide nanocomposites ([email protected]@BSABiS nanoparticles) | dendrimer-stabilized bismuth sulfide nanop
- 锁执行的过程
- 详解C语言中的wait()函数和waitpid()函数
- mmdetection源码解析--ResNet18
- Fragments
- redis 运行lua 脚本 出现Invalid argument(s)
- APP product source data interface (taobao, jingdong/spelling/suning/trill platform details a lot data analysis interface) code and docking tutorial
- 【R语言】对文件进行归一化整理到各文件类型文件夹
- 中英文说明书丨CalBioreagents ACTH N端单克隆抗体
猜你喜欢
随机推荐
Adds, deletes, searches, and changes the leading doubly circular linked list (implemented in C language)
uniapp实现防抖搜索
6 states of a thread
中英文说明书丨CalBioreagents ACTH N端单克隆抗体
pycharm环境包导入到另外一个环境
思维方法 解决问题的能力
static静态关键字和继承
GNNExplainer applied to node classification task
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
cut命令的使用实例
crc calculation
After the VB.net program is closed, the background is still connected to SQL
mmdetection源码解析--ResNet18
Inception V3 闭眼检测
单例 DCL(double check lock) 饱汉模式和饿汉模式
Reverse Engineering
Invalid argument(s) appears when redis runs lua script
DevNet: Deviation Aware Networkfor Lane Detection
Word文件的只读模式没有密码怎么退出?
el-table缓存数据









