270 Closest Binary Search Tree Value
Given a non-empty binary search tree and a target value, find the value in the BST that is closest to the target.
Note:
Given target value is a floating point.
You are guaranteed to have only one unique value in the BST that is closest to the target.
The Idea: Perform a regular binary search, except rather than searching for the element explicitly, continually update the closest difference with the target value.
Complexity: O(logN) time and O(|height|) space
Python Solution
Same idea, but now iterative.
Last updated