forked from algorithm010/algorithm010
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecond.java
More file actions
27 lines (20 loc) · 545 Bytes
/
second.java
File metadata and controls
27 lines (20 loc) · 545 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//题目: 二叉树的中序遍历
//递归
class solution{
public List<Integer> inorderTraversal(TreeNode root){
List<integer> res = new ArrayList<>();
helper(root,res);
return res;
}
public void helper(TreeNode root, List<Integer> res){
if (root == null) {
if (root.left == null) {
helper(root.left, res);
}
res.add(root.val);
if (root.right == null) {
helper(root.right, res);
}
}
}
}