70. Closest Binary Search Tree Value - Jake blog - Java coding practice log (2017)" /> 70. Closest Binary Search Tree Value - Jake blog - Java coding practice log (2017)" />

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.
/** * 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」

240
0 0 240

Further Reading

Post a reply

Log inYou can only comment after that.
Share this page
Back to top