root of a binary search tree: for every node, all values in its left subtree are smaller than its own value and all values in its right subtree are larger. All values are distinct.
Return the smallest difference between the values of any two different nodes in the tree.root=tree_node([20, 10, 30, 5, 14, 25]) → 4
In increasing order the values are 5, 10, 14, 20, 25, 30. Neighbouring gaps are 5, 4, 6, 5, 5, so the smallest is 4, between 10 and 14.
root=tree_node([50, None, 51]) → 1
There are only two nodes, and they differ by 1.
Node.val ≤ 10⁵root=tree_node([20, 10, 30, 5, 14, 25])
4
Run checks the first 3 tests in your browser. Submit checks all 52 tests on the server, hidden ones included.