Solution: Closest Binary Search Tree Value
Understand how to traverse a binary search tree to find the node value closest to a given floating point target. This lesson helps you apply BST characteristics to optimize search paths and manage tie cases. Learn to implement an efficient solution with O(h) time and O(1) space complexities.
We'll cover the following...
We'll cover the following...
Statement
Given the root of a binary search tree and a floating point target value, find the node value in the BST that is closest to target. If there are multiple node values with the same minimum distance to target, return the smallest among them.
Note: The
targetis a floating point number, while all node values are integers.
Constraints:
The number of nodes in the tree is in the range
. Node.val...