669 Trim a Binary Search Tree
Given a binary search tree and the lowest and highest boundaries asL
andR
, trim the tree so that all its elements lies in[L, R]
(R >= L). You might need to change the root of the tree, so the result should return the new root of the trimmed binary search tree.
Example 1:
Example 2:
这题一开始做还以为是直接砍掉,后来认真看了第二个例子才发现是用left或right子树来replace。
Last updated