当前位置:网站首页>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);
}
}
边栏推荐
- MySQL29-数据库其它调优策略
- MySQL combat optimization expert 07 production experience: how to conduct 360 degree dead angle pressure test on the database in the production environment?
- Technology | diverse substrate formats
- [unity] simulate jelly effect (with collision) -- tutorial on using jellysprites plug-in
- Use xtrabackup for MySQL database physical backup
- Solve the problem of remote connection to MySQL under Linux in Windows
- Mysql24 index data structure
- Time in TCP state_ The role of wait?
- ① BOKE
- 高并发系统的限流方案研究,其实限流实现也不复杂
猜你喜欢
16 medical registration system_ [order by appointment]
Super detailed steps to implement Wechat public number H5 Message push
MySQL22-逻辑架构
[after reading the series] how to realize app automation without programming (automatically start Kwai APP)
MySQL combat optimization expert 04 uses the execution process of update statements in the InnoDB storage engine to talk about what binlog is?
MySQL storage engine
Ueeditor internationalization configuration, supporting Chinese and English switching
MySQL 29 other database tuning strategies
What is the current situation of the game industry in the Internet world?
Introduction tutorial of typescript (dark horse programmer of station B)
随机推荐
Unicode decodeerror: 'UTF-8' codec can't decode byte 0xd0 in position 0 successfully resolved
MySQL31-MySQL事务日志
Water and rain condition monitoring reservoir water and rain condition online monitoring
How to make shell script executable
Anaconda3 安装cv2
Mysql36 database backup and recovery
Discriminant model: a discriminant model creation framework log linear model
Super detailed steps to implement Wechat public number H5 Message push
Ueeditor internationalization configuration, supporting Chinese and English switching
Adaptive Bezier curve network for real-time end-to-end text recognition
Bytetrack: multi object tracking by associating every detection box paper reading notes ()
[programmers' English growth path] English learning serial one (verb general tense)
C miscellaneous two-way circular linked list
Const decorated member function problem
MySQL24-索引的数据结构
高并发系统的限流方案研究,其实限流实现也不复杂
Opencv uses freetype to display Chinese
Just remember Balabala
MySQL实战优化高手11 从数据的增删改开始讲起,回顾一下Buffer Pool在数据库里的地位
Complete web login process through filter