当前位置:网站首页>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:
边栏推荐
猜你喜欢
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disab
Xilinx Zynq ZynqMP DNA
安装flask
Go lang1.18入门精炼教程——第一章:环境搭建
Import the pycharm environment package into another environment
中英文说明书丨CalBioreagents ACTH N端单克隆抗体
db.sqlite3 has no "as Data Source" workaround
sql问题解答创建表的语句
运放-运算放大器经典应用电路大全-应用电路大全
分布式id 生成器实现
随机推荐
shardingsphere数据分片配置项说明和示例
Word文件的只读模式没有密码怎么退出?
运放-运算放大器经典应用电路大全-应用电路大全
阿里巴巴官方技术号
APP商品详情源数据接口(淘宝/京东/拼多多/苏宁/抖音等平台详情数据分析接口)代码对接教程
数据库中间件-jdbi
Import the pycharm environment package into another environment
力扣刷题180
缓存技术使用
【R语言】把文件夹下的所有文件提取到特定文件夹
Unity Gobang Game Design and Simple AI (2)
MYSQL Advanced Chapter - Query Interception Analysis, Lock Mechanism, Master-Slave Replication
String.toLowerCase(Locale.ROOT)
static静态关键字和继承
Unity C# 委托——事件,Action,Func的作用和区别
Unity 五子棋游戏设计和简单AI(2)
分布式id 生成器实现
字节跳动笔试题2020 (抖音电商)
抗菌药物丨Toronto Research Chemicals 天冬酰胺D
【Feel】In the Unity Feel plugin, Camera cannot display CameraShake correctly