一、题目
二叉树中序遍历。

二、思路
1、中序遍历是:左根右的顺序。前序遍历是:根左右的顺序。后序遍历是:左右根的顺序。
2、递归的方式。
三、代码
class Solution {
List<Integer> res = new LinkedList<>();
public List<Integer> inorderTraversal(TreeNode root) {
if(root == null) return res;
inorderTraversal(root.left);
res.add(root.val);
inorderTraversal(root.right);
return res;
}
}
715

被折叠的 条评论
为什么被折叠?



