Class Solution
java.lang.Object
g1301_1400.s1382_balance_a_binary_search_tree.Solution
1382 - Balance a Binary Search Tree.<p>Medium</p>
<p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every node never differs by more than <code>1</code>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/08/10/balance1-tree.jpg" alt="" /></p>
<p><strong>Input:</strong> root = [1,null,2,null,3,null,4,null,null]</p>
<p><strong>Output:</strong> [2,1,3,null,null,null,4]</p>
<p><strong>Explanation:</strong> This is not the only correct answer, [3,1,4,null,2] is also correct.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/08/10/balanced2-tree.jpg" alt="" /></p>
<p><strong>Input:</strong> root = [2,1,3]</p>
<p><strong>Output:</strong> [2,1,3]</p>
<p><strong>Constraints:</strong></p>
<ul>
<li>The number of nodes in the tree is in the range <code>[1, 10<sup>4</sup>]</code>.</li>
<li><code>1 <= Node.val <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
balanceBST
-