Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

inorder traversal

class Solution {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<Integer>();
        return dfs(root, list);
    }
    private List<Integer> dfs(TreeNode root, List<Integer> list)
    {
        if(root == null)
            return list;
        list = dfs(root.left, list);
        list.add(root.val);
        return dfs(root.right,list);
    }
}
Source by leetcode.com #
 
PREVIOUS NEXT
Tagged: #inorder #traversal
ADD COMMENT
Topic
Name
8+9 =