# Python easy understand solution

• Just inorder travel the tree.
Note: There are at least two nodes in this BST.

``````def getMinimumDifference(self, root):
def dfs(node, l=[]):
if node.left: dfs(node.left, l)
l.append(node.val)
if node.right: dfs(node.right, l)
return l
l = dfs(root)
return min([abs(a-b) for a,b in zip(l, l[1:])])
``````

If it's not a BST, just apply `l = sorted(bfs(root))`

• what is the different between these two solutions in principle

• @ZhengwuFang If it is not BST, the order is random.

• @lee215 sorted() makes this solution O(NlogN)

• @albert_001 I didn't use sort in this solution. Sort is only used when it's not a BST

• @lee215 Will level order traversal work?

• @ameya.shanbhag
I don't think so.

• Function name bfs() is confusing. This is not breadth-first search. It's DFS.

• @algowl Agree. Edited.

• convert tree to list and calculate the minimum difference .that 's a good one and straight forward .

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