Class Solution
java.lang.Object
g0601_0700.s0669_trim_a_binary_search_tree.Solution
669 - Trim a Binary Search Tree.<p>Medium</p>
<p>Given the <code>root</code> of a binary search tree and the lowest and highest boundaries as <code>low</code> and <code>high</code>, trim the tree so that all its elements lies in <code>[low, high]</code>. Trimming the tree should <strong>not</strong> change the relative structure of the elements that will remain in the tree (i.e., any node’s descendant should remain a descendant). It can be proven that there is a <strong>unique answer</strong>.</p>
<p>Return <em>the root of the trimmed binary search tree</em>. Note that the root may change depending on the given bounds.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/09/trim1.jpg" alt="" /></p>
<p><strong>Input:</strong> root = [1,0,2], low = 1, high = 2</p>
<p><strong>Output:</strong> [1,null,2]</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2020/09/09/trim2.jpg" alt="" /></p>
<p><strong>Input:</strong> root = [3,0,4,null,2,null,null,1], low = 1, high = 3</p>
<p><strong>Output:</strong> [3,2,null,1]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of nodes in the tree in the range <code>[1, 10<sup>4</sup>]</code>.</li>
<li><code>0 <= Node.val <= 10<sup>4</sup></code></li>
<li>The value of each node in the tree is <strong>unique</strong>.</li>
<li><code>root</code> is guaranteed to be a valid binary search tree.</li>
<li><code>0 <= low <= high <= 10<sup>4</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
trimBST
-