题目:https://leetcode-cn.com/problems/binary-tree-inorder-traversal/
代码:
class Solution { public List<Integer> inorderTraversal(TreeNode root) { List<Integer> res = new ArrayList<>(); if (root != null) { res.addAll(this.inorderTraversal(root.left)); res.add(root.val); res.addAll(this.inorderTraversal(root.right)); } return res; } }
二叉树的前中后序回顾参考:二叉树及二叉树的前序、中序、后序遍历
使用递归很快就能解答出来,前序跟后序只要相对应的调整代码中红色部分3行代码的顺序即可。