Run Code can Accept, but Submit is Error(JavaScript)


  • 0
    Z

    /**

    • Definition for a binary tree node.
    • function TreeNode(val) {
    • this.val = val;
      
    • this.left = this.right = null;
      
    • }
      /
      /
      *
    • @param {TreeNode} root
    • @return {number}
      */
      var arr = [];
      var getMinimumDifference = function(root) {
      mid(root);
      let min = Number.MAX_VALUE;
      for(let i = 1; i < arr.length; i++){
      let diff = Math.abs(arr[i] - arr[i-1]);
      if(min > diff){
      min = diff;
      }
      }
      return min;
      };
      var mid = function(root){
      if(root != null){
      mid(root.left);
      arr.push(root.val);
      mid(root.right);
      }
      }

    Run Code is no problem, but is Submit Solution is failed


Log in to reply
 

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