Description
Given the root of a Binary Search Tree, return the minimum difference between the values of any two different nodes in the tree.
Examples
Input:
root = [4,2,6,1,3]Output:
1Explanation:
Min diff between 2 and 3.
Input:
root = [10,5,15,3,7,null,18]Output:
2Explanation:
The minimum difference is 2, which occurs between nodes 5 and 7. Other differences include: 7-5=2, 10-7=3, 15-10=5, etc.
Input:
root = [27,null,34,null,58,50,null]Output:
7Explanation:
The in-order values are [27,34,50,58], so the adjacent differences are [7,16,8] and the exact minimum difference is 7.
Constraints
- •
2 ≤ nodes ≤ 100