当前位置:网站首页>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:
边栏推荐
- Simple to use Lambda expressions
- 力扣刷题180
- Service
- CMake中INSTALL_RPATH与BUILD_RPATH问题
- Introduction and use of BeautifulSoup4
- Adds, deletes, searches, and changes the leading doubly circular linked list (implemented in C language)
- APP product source data interface (taobao, jingdong/spelling/suning/trill platform details a lot data analysis interface) code and docking tutorial
- Unity 五子棋游戏设计和简单AI(2)
- APP商品详情源数据接口(淘宝/京东/拼多多/苏宁/抖音等平台详情数据分析接口)代码对接教程
- Unity Gobang Game Design and Simple AI (2)
猜你喜欢
什么是excel文件保护
线程的6种状态
Excel受保护的工作表怎么操作?
报错:FSADeprecationWarning: SQLALCHEMY_TRACK_MODIFICATIONS重大开销和将disab补充道
sql问题解答创建表的语句
idea中PlantUML插件使用
Flask failed to create database without error
redis 运行lua 脚本 出现Invalid argument(s)
【Feel】In the Unity Feel plugin, Camera cannot display CameraShake correctly
中英文说明书丨CalBioreagents ACTH N端单克隆抗体
随机推荐
redis 运行lua 脚本 出现Invalid argument(s)
AD的library中 库文件后缀有.intlib .schlib .pcblib 的区别
flask创建数据库失败未报错
install flask
按图搜索1688商品接口(item_search_img-按图搜索1688商品(拍立淘接口)代码对接教程
el-table缓存数据
shardingsphere data sharding configuration item description and example
单例 DCL(double check lock) 饱汉模式和饿汉模式
如何操作数据库
Redis 2 - 高级
锁执行的过程
Word文件的只读模式没有密码怎么退出?
报错jinja2.exceptions.UndefinedError: ‘form‘ is undefined
P7阿里面试题2020.07 之滑动窗算法(阿里云面试)
[R language] interaction test data
VS2019常用快捷键
治疗消化性溃疡—Toronto Research Chemicals 甘氨酸铝
线程的6种状态
安装flask
Unity五子棋游戏设计 和简单AI实现(1)