```
class Solution:
def trimBST(self, root, L, R):
"""
:type root: TreeNode
:type L: int
:type R: int
:rtype: TreeNode
"""
def helper(node):
if node is None:
return None
if node.val > R:
return helper(node.left)
if node.val < L:
return helper(node.right)
node.left, node.right = helper(node.left), helper(node.right)
return node
return helper(root)
```