当前位置:网站首页>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);
}
}
边栏推荐
- [paper reading notes] - cryptographic analysis of short RSA secret exponents
- MySQL26-性能分析工具的使用
- MNIST implementation using pytoch in jupyter notebook
- Implement sending post request with form data parameter
- 评估方法的优缺点
- Pytorch LSTM实现流程(可视化版本)
- Mysql32 lock
- MySQL real battle optimization expert 08 production experience: how to observe the machine performance 360 degrees without dead angle in the process of database pressure test?
- [C language] deeply analyze the underlying principle of data storage
- MySQL实战优化高手05 生产经验:真实生产环境下的数据库机器配置如何规划?
猜你喜欢

C miscellaneous two-way circular linked list

Mysql33 multi version concurrency control

MySQL实战优化高手04 借着更新语句在InnoDB存储引擎中的执行流程,聊聊binlog是什么?

MySQL27-索引優化與查詢優化

Not registered via @enableconfigurationproperties, marked (@configurationproperties use)

Use JUnit unit test & transaction usage

Mysql32 lock
![15 medical registration system_ [appointment registration]](/img/c1/27c7a5aae82783535e5467583bb176.png)
15 medical registration system_ [appointment registration]

Opencv uses freetype to display Chinese
![[after reading the series of must know] one of how to realize app automation without programming (preparation)](/img/eb/e789d88f10787c302f9457ca7ca2cc.jpg)
[after reading the series of must know] one of how to realize app automation without programming (preparation)
随机推荐
Mysql28 database design specification
How to make shell script executable
Mysql35 master slave replication
Technology | diverse substrate formats
实现以form-data参数发送post请求
MySQL combat optimization expert 06 production experience: how does the production environment database of Internet companies conduct performance testing?
Pytoch LSTM implementation process (visual version)
Complete web login process through filter
ByteTrack: Multi-Object Tracking by Associating Every Detection Box 论文阅读笔记()
Software test engineer development planning route
MySQL实战优化高手10 生产经验:如何为数据库的监控系统部署可视化报表系统?
Chrome浏览器端跨域不能访问问题处理办法
C miscellaneous two-way circular linked list
PyTorch RNN 实战案例_MNIST手写字体识别
MySQL 29 other database tuning strategies
Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
Mysql30 transaction Basics
Export virtual machines from esxi 6.7 using OVF tool
Google login prompt error code 12501
Opencv uses freetype to display Chinese