Created
April 24, 2018 14:11
-
-
Save s4553711/d6e9e428cdade499ed6885e6222f0223 to your computer and use it in GitHub Desktop.
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
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
public: | |
TreeNode* trimBST(TreeNode* root, int L, int R) { | |
if (!root) return nullptr; | |
if (root->val < L) return trimBST(root->right, L, R); | |
if (root->val > R) return trimBST(root->left, L, R); | |
root->left = trimBST(root->left, L, R); | |
root->right = trimBST(root->right, L, R); | |
return root; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment