Skip to content

Instantly share code, notes, and snippets.

@j0nathanB
Created December 12, 2017 16:15
Show Gist options
  • Select an option

  • Save j0nathanB/3a16295bbc8a154d4037b7c8e6a1c9c9 to your computer and use it in GitHub Desktop.

Select an option

Save j0nathanB/3a16295bbc8a154d4037b7c8e6a1c9c9 to your computer and use it in GitHub Desktop.
Trim BST
var trimBST = function(root, L, R) {
if (root === null) {
return null;
}
root.left = trimBST(root.left, L, R);
root.right = trimBST(root.right, L, R);
if (root.val < L) {
return root.right;
}
if (root.val > R) {
return root.left;
}
return root;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment