530. Minimum Absolute Difference in BST
Python
from math import inf
class Solution:
def getMinimumDifference(self, root: Optional[TreeNode]) -> int:
def dfs(node, upper, lower):
if not node:
return upper - lower
return min(
dfs(node.left, node.val, lower),
dfs(node.right, upper, node.val)
)
return dfs(root, inf, -inf)