6 Lines Python Solution by converting BST to ordered list using recursion


  • 1
    F
    class Solution(object):
        def bstToList(self, root):
            if not root:
                return []
            return self.bstToList(root.left) + [root.val] +  self.bstToList(root.right)
             
        def getMinimumDifference(self, root):
            nodes = self.bstToArray(root)
            return min([abs(a-b) for a,b in zip(nodes, nodes[1:])])
    

Log in to reply
 

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