Given the root of a Binary Search Tree (BST), return the minimum 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, 100].
	0 &lt;= Node.val &lt;= 105


&nbsp;
Note: This question is the same as 530: https://leetcode.com/problems/minimum-absolute-difference-in-bst/

# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def minDiffInBST(self, root: Optional[TreeNode]) -> int:
        if root is None:
            return 0
        temp1=float(inf)
        from collections import deque
        a=deque([root])
        b=[]
        while a:
            node=a.popleft()
            b.append(node.val)
            if node.left:
                a.append(node.left)
            if node.right:
                a.append(node.right)
        b.sort()
        for i in range(0,len(b)-1):
            if b[i+1]-b[i]
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    
    int mini=Integer.MAX_VALUE;

    public void find(TreeNode root,ArrayList<Integer>arr){
    
    if(root==null){
        return;
    }
    
    
    arr.add(root.val);
    
    find(root.left,arr);
    
    for(int i=arr.size()-2;i>=0;i--){
    
        mini=Math.min(mini,Math.abs(root.val-arr.get(i)));
    }
    
    find(root.right,arr);
    
    arr.remove(arr.size()-1);
    }

    public int minDiffInBST(TreeNode root) {
    ArrayList<Integer>arr=new ArrayList<>();
    find(root,arr);
    return mini;    
    }
}
class Solution {
    int minDiff=INT_MAX,prev=INT_MAX;
public:
    void inorder(TreeNode* p){
        if(p==NULL) return;
        inorder(p->left);
        minDiff=min(minDiff,abs(p->val-prev));
        prev=p->val;
        inorder(p->right);
    }
    int minDiffInBST(TreeNode* root) {
        inorder(root);
        return minDiff;
    }
};
/**
 * @param {TreeNode} root
 * @return {number}
 */
var minDiffInBST = function(root) {
    let arr = [];
    
	const helper = (node) => {
		if (node) {
			helper(node.left);
			arr.push(node.val);
			helper(node.right);
		}
	}
	helper(root);
    
	let min = Infinity;
	for (let i = 0; i < arr.length - 1; i++) {
		const diff = Math.abs(arr[i] - arr[i + 1]);
		min = Math.min(min, diff);
	}
    
	return min;
};
Minimum Distance Between BST Nodes