01 · Question
Find the value in a BST that is closest to the target.
02 · Solution
1def closestValue(root: Optional[TreeNode], target: float) -> int:2 closest = root.val3 cur = root4 while cur:5 if abs(cur.val - target) < abs(closest - target):6 closest = cur.val7 cur = cur.left if target < cur.val else cur.right8 return closest