QuestionGiven therootof a binary search tree and atargetvalue, returnthe value in the BST that is closest to thetarget. If there are multiple answers, print the smallest.Example 1:Input: root = [4,2,5,1,3], target = 3.714286
Output: 4AlgorithmEasy question. Traverse the tree and compare and record the smallest absolute value from the target and the node value.Code/*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode() {}* TreeNode(int val) { this.val = val; }* TreeNode(int val, TreeNode left, TreeNode right
...
继续阅读
(16)