Question 94. Binary Tree Inorder Traversal
Given a binary tree, return the inorder traversal of its nodes’ values.
For example:
Given binary tree [1,null,2,3],1
\
2
/
3
return [1,3,2].二叉树的中序遍历
和先序遍历基本一样,只是改成中序遍历:
/**
* @param root
* @return
*/
public static List<Integer> inorderTraversal(TreeNode root) {
List<Integer> res= new ArrayList<Integer>();
inHelper(root, res);
return res;
}
private static void inHelper(TreeNode root, List<Integer> in) {
if(root==null) return;
inHelper(root.left, in);
in.add(root.val);
inHelper(root.right,in);
}