Run-time Error for JavaScript solution


  • 0
    J

    I've got run-time error for my JavaScript solution which runs fine on my local machine.
    There is errors for the most basic test case, [4, 2, 6, 3, 1, 5], 1, 2. So I was wondering what's wrong with my code? And is JavaScript run-time on LeetCode differs a lot from my local machine one(Nodejs v7.9.0)?

    
    var addOneRow = function(root, v, d) {
      if (root) {
        transversal(root, 1, d - 1, v);
      }
      return root;
    };
    
    function transversal(node, cd, d, v) {
      if (node) {
        if (cd === d) {
          node.left =  { val: v, left: node.left,   right: null };
          node.right = { val: v, right: node.right, right: null };
        } else {
          transversal(node.left,  cd + 1, d, v);
          transversal(node.right, cd + 1, d, v);
        }
      }
    }
    

Log in to reply
 

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