[LeetCode] Closest Binary Search Tree Value - jcliBlogger - 博客园
[LeetCode] Closest Binary Search Tree Value
Problem Description:
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.
Well, this problem can be solved easily using recursion: just find the closest value in the left and right subtrees and compare them with root -> val. The code is as follows.
Read full article from [LeetCode] Closest Binary Search Tree Value - jcliBlogger - 博客园
No comments:
Post a Comment