当前位置:网站首页>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);
}
}
边栏推荐
- Mysql27 index optimization and query optimization
- MySQL实战优化高手10 生产经验:如何为数据库的监控系统部署可视化报表系统?
- [after reading the series] how to realize app automation without programming (automatically start Kwai APP)
- MySQL27-索引优化与查询优化
- Sed text processing
- Discriminant model: a discriminant model creation framework log linear model
- MySQL21-用户与权限管理
- 软件测试工程师必备之软技能:结构化思维
- [programmers' English growth path] English learning serial one (verb general tense)
- MySQL22-逻辑架构
猜你喜欢
In fact, the implementation of current limiting is not complicated
Mysql35 master slave replication
The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?
MySQL27-索引优化与查询优化
ByteTrack: Multi-Object Tracking by Associating Every Detection Box 论文阅读笔记()
How to change php INI file supports PDO abstraction layer
Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
MySQL storage engine
Database middleware_ MYCAT summary
随机推荐
Mysql30 transaction Basics
[after reading the series] how to realize app automation without programming (automatically start Kwai APP)
如何搭建接口自动化测试框架?
Sed text processing
[paper reading notes] - cryptographic analysis of short RSA secret exponents
MySQL combat optimization expert 02 in order to execute SQL statements, do you know what kind of architectural design MySQL uses?
MySQL26-性能分析工具的使用
MySQL29-数据库其它调优策略
Case identification based on pytoch pulmonary infection (using RESNET network structure)
解决在window中远程连接Linux下的MySQL
14 medical registration system_ [Alibaba cloud OSS, user authentication and patient]
C language string function summary
Mysql32 lock
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xd0 in position 0成功解决
① BOKE
ByteTrack: Multi-Object Tracking by Associating Every Detection Box 论文阅读笔记()
【C语言】深度剖析数据存储的底层原理
How to build an interface automation testing framework?
MySQL27-索引優化與查詢優化
Ueeditor internationalization configuration, supporting Chinese and English switching