Python Solution


  • 0
    D
    def find_min(x):
        while x.left != None:
            x = x.left
        else:
            return x.val
        
    def find_max(x):
        while x.right != None:
            x = x.right
        else:
            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.