trimBST(node, low, high)
that takes the current node and the range [low, high]
as arguments.node
is null
, return null
.node.val
is less than low
, return the result of trimBST(node.right, low, high)
.node.val
is greater than high
, return the result of trimBST(node.left, low, high)
.node
with trimBST(node.left, low, high)
and trimBST(node.right, low, high)
, respectively.node.left
and node.right
with the trimmed subtrees.node
as it is within the range and now has the correct trimmed subtrees.