代码随想录算法训练营Day23
669. Trim a Binary Search Tree
class Solution:
def trimBST(self, root: Optional[TreeNode], low: int, high: int) -> Optional[TreeNode]:
if not root: return None
if root.val < low: root = self.trimBST(root.right, low, high)
elif root.val > high: root = self.trimBST(root.left, low, high)
else:
root.left = self.trimBST(