Problem
Given the root of a binary search tree (every node's left subtree holds smaller values and its right subtree holds larger values), return the smallest difference between the values of any two different nodes.
Trees in the examples are written in level order (top to bottom, left to right), with null for a missing child, the same way the tests build them.
Example 1
- Input
- [8, 4, 13, 2, 6]
- Output
- 2
- Why
- 4 and 6, or 4 and 2, or 6 and 8
Example 2
- Input
- [10, 3, 40, null, null, 21, 45]
- Output
- 5
- Why
- 40 and 45
Example 3
- Input
- [1, null, 100000]
- Output
- 99999
Constraints
2 <= number of nodes <= 10^40 <= Node.val <= 10^5All values are distinct.