当前位置:网站首页>February 13, 2022-3-middle order traversal of binary tree
February 13, 2022-3-middle order traversal of binary tree
2022-07-06 10:36:00 【Procedural ape does not lose hair 2】
Given the root node of a binary tree root , Back to its Middle preface Traverse .
Example 1:
Input :root = [1,null,2,3]
Output :[1,3,2]
Example 2:
Input :root = []
Output :[]
Example 3:
Input :root = [1]
Output :[1]
Example 4:
Input :root = [1,2]
Output :[2,1]
Example 5:
Input :root = [1,null,2]
Output :[1,2]
Tips :
The number of nodes in the tree is in the range [0, 100] Inside
-100 <= Node.val <= 100
java Code :
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode() {}
* TreeNode(int val) { this.val = val; }
* TreeNode(int val, TreeNode left, TreeNode right) {
* this.val = val;
* this.left = left;
* this.right = right;
* }
* }
*/
class Solution {
public List<Integer> inorderTraversal(TreeNode root) {
List<Integer> res = new ArrayList<Integer>();
inorder(root, res);
return res;
}
public void inorder(TreeNode root, List<Integer> res) {
if (root == null) {
return;
}
inorder(root.left, res);
res.add(root.val);
inorder(root.right, res);
}
}
边栏推荐
- Sed text processing
- 数据库中间件_Mycat总结
- MySQL实战优化高手06 生产经验:互联网公司的生产环境数据库是如何进行性能测试的?
- UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd0 in position 0成功解决
- MNIST implementation using pytoch in jupyter notebook
- 13 medical registration system_ [wechat login]
- Typescript入门教程(B站黑马程序员)
- Mysql34 other database logs
- Bytetrack: multi object tracking by associating every detection box paper reading notes ()
- Const decorated member function problem
猜你喜欢
![16 medical registration system_ [order by appointment]](/img/7f/d94ac2b3398bf123bc97d44499bb42.png)
16 medical registration system_ [order by appointment]

A necessary soft skill for Software Test Engineers: structured thinking

The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant

Mysql36 database backup and recovery

Mysql25 index creation and design principles

Complete web login process through filter

用于实时端到端文本识别的自适应Bezier曲线网络

Super detailed steps for pushing wechat official account H5 messages

Use JUnit unit test & transaction usage

MySQL实战优化高手12 Buffer Pool这个内存数据结构到底长个什么样子?
随机推荐
MySQL combat optimization expert 07 production experience: how to conduct 360 degree dead angle pressure test on the database in the production environment?
Time complexity (see which sentence is executed the most times)
颜值爆表,推荐两款JSON可视化工具,配合Swagger使用真香
MySQL24-索引的数据结构
Mysql32 lock
如何搭建接口自动化测试框架?
The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
数据库中间件_Mycat总结
UEditor国际化配置,支持中英文切换
PyTorch RNN 实战案例_MNIST手写字体识别
14 medical registration system_ [Alibaba cloud OSS, user authentication and patient]
评估方法的优缺点
Technology | diverse substrate formats
该不会还有人不懂用C语言写扫雷游戏吧
Use JUnit unit test & transaction usage
Isn't there anyone who doesn't know how to write mine sweeping games in C language
MySQL21-用户与权限管理
Software test engineer development planning route
C miscellaneous dynamic linked list operation
Download and installation of QT Creator