My idea is easy,like greedy in some way.

what I do is to make sure root val is in [L,R]

class Solution {

public:

TreeNode* trimBST(TreeNode* root, int L, int R) {

while(root&&(root->val<L||root->val>R))root=root->val<L?root->right:root->left;

if(root){

root->left=trimBST(root->left,L,R);

root->right=trimBST(root->right,L,R);

}

return root;

}

};