← 返回 meta 的题目列表Find Closest Node in a BST
类型:online_judge
Given a binary search tree (BST) and a target value target, find the node in the tree that is closest to the target value.
Input
root: A TreeNode representing the root of the BST.
target: A double float type number.
Output
Return an integer representing the value of the node closest to the target value in the tree.
Example
Input:
BST structure:
10
/ \
5 15
/ \ / \
2 7 12 20
target = 11
Output: 12
Note
Each tree node value is unique.
Example
Input
10 5 2 7 15 12 20
11