@@ -0,0 +1,1405 @@
+# Time:  O(n)%0A# Space: O(h)%0A%0A# Given a Binary Search Tree (BST) with the root node root,%0A# return the minimum difference between the values of any two different nodes in the tree.%0A#%0A# Example :%0A#%0A# Input: root = %5B4,2,6,1,3,null,null%5D%0A# Output: 1%0A# Explanation:%0A# Note that root is a TreeNode object, not an array.%0A#%0A# The given tree %5B4,2,6,1,3,null,null%5D is represented by the following diagram:%0A#%0A#           4%0A#         /   %5C%0A#       2      6%0A#      / %5C    %0A#     1   3  %0A#%0A# while the minimum difference in this tree is 1,%0A# it occurs between node 1 and node 2, also between node 3 and node 2.%0A#%0A# Note:%0A# - The size of the BST will be between 2 and 100.%0A# - The BST is always valid, each node's value is an integer, and each node's value is different.%0A%0A# Definition for a binary tree node.%0A# class TreeNode(object):%0A#     def __init__(self, x):%0A#         self.val = x%0A#         self.left = None%0A#         self.right = None%0A%0Aclass Solution(object):%0A    def minDiffInBST(self, root):%0A        %22%22%22%0A        :type root: TreeNode%0A        :rtype: int%0A        %22%22%22%0A        def dfs(node):%0A            if not node:%0A                return%0A            dfs(node.left)%0A            self.result = min(self.result, node.val-self.prev)%0A            self.prev = node.val%0A            dfs(node.right)%0A%0A        self.prev = float('-inf')%0A        self.result = float('inf')%0A        dfs(root)%0A        return self.result%0A        %0A

Create minimum-distance-between-bst-nodes.py