当前位置:网站首页>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);
}
}
边栏推荐
- Global and Chinese market of operational amplifier 2022-2028: Research Report on technology, participants, trends, market size and share
- Introduction tutorial of typescript (dark horse programmer of station B)
- Pytoch LSTM implementation process (visual version)
- 基于Pytorch的LSTM实战160万条评论情感分类
- Set shell script execution error to exit automatically
- MySQL实战优化高手02 为了执行SQL语句,你知道MySQL用了什么样的架构设计吗?
- MySQL combat optimization expert 02 in order to execute SQL statements, do you know what kind of architectural design MySQL uses?
- Solution to the problem of cross domain inaccessibility of Chrome browser
- The underlying logical architecture of MySQL
- MySQL实战优化高手10 生产经验:如何为数据库的监控系统部署可视化报表系统?
猜你喜欢

Pytorch LSTM实现流程(可视化版本)

MySQL實戰優化高手04 借著更新語句在InnoDB存儲引擎中的執行流程,聊聊binlog是什麼?

Case identification based on pytoch pulmonary infection (using RESNET network structure)

C miscellaneous shallow copy and deep copy

软件测试工程师必备之软技能:结构化思维

解决在window中远程连接Linux下的MySQL

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

MySQL storage engine

Export virtual machines from esxi 6.7 using OVF tool

保姆级手把手教你用C语言写三子棋
随机推荐
14 medical registration system_ [Alibaba cloud OSS, user authentication and patient]
What is the current situation of the game industry in the Internet world?
Mysql32 lock
Water and rain condition monitoring reservoir water and rain condition online monitoring
软件测试工程师必备之软技能:结构化思维
MySQL24-索引的数据结构
CDC: the outbreak of Listeria monocytogenes in the United States is related to ice cream products
MySQL实战优化高手10 生产经验:如何为数据库的监控系统部署可视化报表系统?
Anaconda3 安装cv2
颜值爆表,推荐两款JSON可视化工具,配合Swagger使用真香
How to make shell script executable
13 medical registration system_ [wechat login]
第一篇博客
MySQL combat optimization expert 05 production experience: how to plan the database machine configuration in the real production environment?
MySQL ERROR 1040: Too many connections
数据库中间件_Mycat总结
Use xtrabackup for MySQL database physical backup
Implement sending post request with form data parameter
Not registered via @EnableConfigurationProperties, marked(@ConfigurationProperties的使用)
MySQL27-索引优化与查询优化