当前位置:网站首页>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);
}
}
边栏推荐
- MNIST implementation using pytoch in jupyter notebook
- Ueeditor internationalization configuration, supporting Chinese and English switching
- [paper reading notes] - cryptographic analysis of short RSA secret exponents
- 数据库中间件_Mycat总结
- MySQL storage engine
- MySQL transaction log
- 【C语言】深度剖析数据存储的底层原理
- MySQL的存储引擎
- MySQL ERROR 1040: Too many connections
- C miscellaneous lecture continued
猜你喜欢

MySQL32-锁

MySQL combat optimization expert 02 in order to execute SQL statements, do you know what kind of architectural design MySQL uses?
![[unity] simulate jelly effect (with collision) -- tutorial on using jellysprites plug-in](/img/1f/93a6c6150ec2b002f667a882569b7b.jpg)
[unity] simulate jelly effect (with collision) -- tutorial on using jellysprites plug-in

MySQL real battle optimization expert 11 starts with the addition, deletion and modification of data. Review the status of buffer pool in the database

MySQL26-性能分析工具的使用

Mysql27 index optimization and query optimization

Mysql23 storage engine

Database middleware_ MYCAT summary

UEditor国际化配置,支持中英文切换

Complete web login process through filter
随机推荐
【C语言】深度剖析数据存储的底层原理
MySQL实战优化高手06 生产经验:互联网公司的生产环境数据库是如何进行性能测试的?
实现微信公众号H5消息推送的超级详细步骤
What is the difference between TCP and UDP?
Implement context manager through with
Jar runs with error no main manifest attribute
MySQL ERROR 1040: Too many connections
MySQL33-多版本并发控制
[Julia] exit notes - Serial
Opencv uses freetype to display Chinese
ByteTrack: Multi-Object Tracking by Associating Every Detection Box 论文阅读笔记()
MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?
What is the current situation of the game industry in the Internet world?
Const decorated member function problem
MySQL26-性能分析工具的使用
MySQL22-逻辑架构
Preliminary introduction to C miscellaneous lecture document
基于Pytorch的LSTM实战160万条评论情感分类
Security design verification of API interface: ticket, signature, timestamp
高并发系统的限流方案研究,其实限流实现也不复杂