For example:
Given binary tree {1,#,2,3}
,
1 \ 2 / 3
return [1,3,2]
.
public class Solution {
public List<Integer> inorderTraversal(TreeNode root) {
List<Integer> res = new ArrayList<Integer>();
if(root==null) return res;
if(root.left!=null){
res.addAll(inorderTraversal(root.left));
}
res.add(root.val);
if(root.right!=null){
res.addAll(inorderTraversal(root.right));
}
return res;
}
}