My Recursive Java solution


  • 0
    S

    public List<Integer> preOrderList = new LinkedList<Integer>();
    public List<Integer> preorderTraversal1(TreeNode root) {
    if (root!=null) {
    preOrderList.add(root.val);
    preorderTraversal1(root.left);
    preorderTraversal1(root.right);

    }
    return preOrderList;
    }


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.