Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.

&nbsp;
Example 1:

Input: root = [4,2,6,1,3]
Output: 1


Example 2:

Input: root = [1,0,48,null,null,12,49]
Output: 1


&nbsp;
Constraints:


	The number of nodes in the tree is in the range [2, 104].
	0 &lt;= Node.val &lt;= 105


&nbsp;
Note: This question is the same as 783: https://leetcode.com/problems/minimum-distance-between-bst-nodes/

class Solution:
    def getMinimumDifference(self, root: Optional[TreeNode]) -> int:
        cur, stack, minDiff, prev = root, [], 10**5, -10**5
        
        while stack or cur:
            while cur:
                stack.append(cur)
                cur = cur.left
            node = stack.pop()
            minDiff = min(minDiff, node.val - prev)
            prev = node.val
            cur = node.right
        
        return minDiff
class Solution {
    public int getMinimumDifference(TreeNode root) {
      Queue<Integer> queue=new PriorityQueue<>();
      Queue<TreeNode> nodesQueue=new LinkedList<>();
      int min=Integer.MAX_VALUE;
      if(root==null)
        return 0;
      nodesQueue.add(root);
      while(!nodesQueue.isEmpty())
      {
        TreeNode node=nodesQueue.poll();
        queue.add(node.val);
        if(node.left!=null)
        { 
          nodesQueue.add(node.left);
        }
        if(node.right!=null)
        { 
          nodesQueue.add(node.right);
        }
      }
      int prev=queue.poll();
      while(!queue.isEmpty())
      {
        int current=queue.poll();
        int absValue=Math.abs(current-prev);
        prev=current;
        min=Math.min(min,absValue);
        
      } 
      return min;
    }
}
class Solution {
    TreeNode* pre = nullptr;
    int minimum = std::numeric_limits<int>:: max();
public:
    void inorder(TreeNode* node) {
        if (!node) return;
        inorder(node->left);
        if(pre) {
            minimum = min(node->val - pre->val, minimum);
        }
        pre = node;
        inorder(node->right);
    }
    int getMinimumDifference(TreeNode* root) {
        inorder(root);
        return minimum;
    }

};
var getMinimumDifference = function(root) {
    let order = inOrder(root, []);
    let diff = Math.abs(order[1] - order[0]);
    for(let i=0;i<order.length;i++) {
        for(let j=i+1;j<order.length;j++) {
            if(Math.abs(order[i] - order[j]) < diff) diff = Math.abs(order[i] - order[j])
        }
    }
    return diff;
};

const inOrder = (root, order) => {
    if(!root) return null;
    inOrder(root.left, order);
    order.push(root.val);
    inOrder(root.right, order);
    return order;
}
Minimum Absolute Difference in BST