方法一:递归
class Solution { public List<Integer> inorderTraversal(TreeNode root) { List<Integer> arraylist=new ArrayList<Integer>(); if(root==null){ return arraylist; } List<Integer> left=inorderTraversal(root.left); List<Integer> right=inorderTraversal(root.right); arraylist.addAll(left); arraylist.add(root.val); arraylist.addAll(right); return arraylist; } }
方法二:迭代+栈