Created
December 12, 2017 16:15
-
-
Save j0nathanB/3a16295bbc8a154d4037b7c8e6a1c9c9 to your computer and use it in GitHub Desktop.
Trim BST
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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