中序遍历的递归和迭代写法
递归写法:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
public List<Integer> inorderTraversal(TreeNode root) { List<Integer> res = new ArrayList<>(); inorder(root,res); return res; } private void inorder(TreeNode root,List<Integer> res) { if(root == null) return; inorder(root.left,res); res.add(root.val); inorder(root.right,res); }