当前位置:网站首页>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);
}
}
边栏推荐
- How to change php INI file supports PDO abstraction layer
- MySQL combat optimization expert 04 uses the execution process of update statements in the InnoDB storage engine to talk about what binlog is?
- Just remember Balabala
- Mysql27 index optimization and query optimization
- 评估方法的优缺点
- MySQL实战优化高手05 生产经验:真实生产环境下的数据库机器配置如何规划?
- Mysql35 master slave replication
- The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
- ZABBIX introduction and installation
- What is the current situation of the game industry in the Internet world?
猜你喜欢
解决在window中远程连接Linux下的MySQL
Preliminary introduction to C miscellaneous lecture document
MySQL27-索引優化與查詢優化
数据库中间件_Mycat总结
[Julia] exit notes - Serial
[after reading the series] how to realize app automation without programming (automatically start Kwai APP)
Mysql26 use of performance analysis tools
颜值爆表,推荐两款JSON可视化工具,配合Swagger使用真香
Security design verification of API interface: ticket, signature, timestamp
Mysql27 - Optimisation des index et des requêtes
随机推荐
The appearance is popular. Two JSON visualization tools are recommended for use with swagger. It's really fragrant
Emotional classification of 1.6 million comments on LSTM based on pytoch
Pytorch LSTM实现流程(可视化版本)
Use of dataset of pytorch
MySQL combat optimization expert 02 in order to execute SQL statements, do you know what kind of architectural design MySQL uses?
Bytetrack: multi object tracking by associating every detection box paper reading notes ()
[unity] simulate jelly effect (with collision) -- tutorial on using jellysprites plug-in
Complete web login process through filter
Transactions have four characteristics?
Good blog good material record link
Mysql36 database backup and recovery
[paper reading notes] - cryptographic analysis of short RSA secret exponents
Mysql24 index data structure
Not registered via @enableconfigurationproperties, marked (@configurationproperties use)
16 medical registration system_ [order by appointment]
Google login prompt error code 12501
Vscode common instructions
MySQL combat optimization expert 06 production experience: how does the production environment database of Internet companies conduct performance testing?
15 medical registration system_ [appointment registration]
基于Pytorch肺部感染识别案例(采用ResNet网络结构)