Javascript recursive (12 lines)


  • -2
    E
    var preorderTraversalHelper = function(root,ary) {
        if (root) {
            preorderTraversalHelper(null,ary.push(root.val));
            preorderTraversalHelper(root.left,ary);
            preorderTraversalHelper(root.right,ary);
        }
    };
    var preorderTraversal = function(root) {
      var ary=[];
      preorderTraversalHelper(root,ary);
      return ary;
    };

Log in to reply
 

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