JavaScript recursive solution


  • 2
    var getMinimumDifference = function(root) {
      let pre = undefined;
      let diff = Infinity;
      function inOrder(root) {
        if (root === null) {
          return;
        }
        inOrder(root.left);
        if (pre !== undefined && diff > root.val - pre) {
          diff = root.val - pre;
        }
        pre = root.val;
        inOrder(root.right);
      }
      inOrder(root);
      return diff;
    };

Log in to reply
 

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