Skip to content

Commit

Permalink
*
Browse files Browse the repository at this point in the history
  • Loading branch information
imteekay committed Dec 6, 2023
1 parent 9d1263c commit 580b645
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Runtime: O(N), where N = number of nodes in the tree
// Space: O(1)

function findClosestValueInBst(tree, target, closestValue = null) {
function findClosestValueInBst(tree, target, closestValue = Infinity) {
if (!tree) {
return closestValue;
}

let currentDiff = Math.abs(tree.value - target);
let diff = closestValue ? Math.abs(closestValue - target) : currentDiff;
let diff = Math.abs(closestValue - target);
let leftValue = findClosestValueInBst(
tree.left,
target,
Expand Down

0 comments on commit 580b645

Please sign in to comment.