Practice/Meta/Leetcode 530. Minimum Absolute Difference in BST
CodingMust
You are given the root node of a binary search tree (BST). Your task is to determine the smallest absolute difference between the values of any two distinct nodes in the tree.
A binary search tree is a tree where for every node, all values in its left subtree are smaller than the node's value, and all values in its right subtree are greater than the node's value.
[2, 10^4]0 <= Node.val <= 10^5Example 1:
`
Input: root = [4,2,6,1,3]
Tree structure:
4
/
2 6
/
1 3
Output: 1 Explanation: The minimum difference is 1, occurring between pairs like (1,2), (2,3), or (3,4) `
Example 2:
`
Input: root = [1,0,48,null,null,12,49]
Tree structure:
1
/
0 48
/
12 49
Output: 1 Explanation: The minimum difference is 1, between nodes 48 and 49 `
Example 3:
`
Input: root = [5,3,7]
Tree structure:
5
/
3 7
Output: 2 Explanation: Both differences (5-3=2 and 7-5=2) equal 2 `