my Python solution


  • 1
    M

    class Solution(object):

    def getMinimumDifference(self, root):
        """
        :type root: TreeNode
        :rtype: int
        """
        queue,l=[root],[root.val]
        while queue:
            node=queue.pop()
            if node.left:
                l.append(node.left.val)
                queue.append(node.left)
            if node.right:
                l.append(node.right.val)
                queue.append(node.right)
        ans, l=[],sorted(l)[:]
        for i in range(1,len(l)):
            ans.append(l[i]-l[i-1])
        return min(ans)

Log in to reply
 

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