
Given the root of a binary search tree (BST) and a floating-point number target, return the value in the BST that is closest to target.
If there are multiple values equally close, return the smaller value (or specify a deterministic tie-breaker).
root
: root node of a BST (each node has
val
,
left
,
right
)
target
: a real number
1 .. 10^5
BST values: [4,2,5,1,3], target = 3.714286 → output 4