Data Structure & Algorithm: Level-1 Problem #40. Minimum Difference in BST

Given a binary search tree with positive values, find the minimum absolute difference between values of any two nodes.

Sample Input:

root =[18, 7, 25, 2, 13, None, 34, None, None, 10, 16, 29]

Sample Output:

2

In the given sample BST tree, the minimum difference is between node value 16 and 18, which is 2.

Min-Difference in BST

数据结构和算法:初级练习题 #40 – 二叉搜索树最小差值

给定一颗二叉搜索树,找出任何两个结点之间的最小差值。

输入样例:

root =[18, 7, 25, 2, 13, None, 34, None, None, 10, 16, 29]

输出样例:

2

在上面的输入样例中,结点16和18之间的差值2是整个二叉搜索树所有结点的最小差值。

Python Solution

Minimum Difference in BST