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.
/** * Definition for a binary tree node. * public class TreeNode { * int val; Math.abs(target-root.val)){ res = root.val; abs = Math.abs(target-root.val); } if(target This siteOriginal articleAll follow "Attribution-NonCommercial-ShareAlike 4.0 License (CC BY-NC-SA 4.0)Please retain the following annotations when sharing or adapting:
Original author:Jake Tao,source:「270. Closest Binary Search Tree Value」