Python Solution

  • 0
    def find_min(x):
        while x.left != None:
            x = x.left
            return x.val
    def find_max(x):
        while x.right != None:
            x = x.right
            return x.val
    def myGetMinimumDifference(root):
        min_value = float('inf')
        if root.left == None and root.right == None:
            return float('inf')
        if root.right != None:
            min_value = abs(root.val-find_min(root.right))
            min_value = min(min_value,myGetMinimumDifference(root.right))
        if root.left != None:
            min_value = min(min_value,abs(find_max(root.left) - root.val))
            min_value = min(min_value,myGetMinimumDifference(root.left))
        return min_value

Log in to reply

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