java.lang.Object
g0101_0200.s0108_convert_sorted_array_to_binary_search_tree.Solution

public class Solution extends Object
108 - Convert Sorted Array to Binary Search Tree.<p>Easy</p> <p>Given an integer array <code>nums</code> where the elements are sorted in <strong>ascending order</strong> , convert <em>it to a <strong>height-balanced</strong> binary search tree</em>.</p> <p>A <strong>height-balanced</strong> binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/02/18/btree1.jpg" alt="" /></p> <p><strong>Input:</strong> nums = [-10,-3,0,5,9]</p> <p><strong>Output:</strong> [0,-3,9,-10,null,5]</p> <p><strong>Explanation:</strong> [0,-10,5,null,-3,null,9] is also accepted: <img src="https://assets.leetcode.com/uploads/2021/02/18/btree2.jpg" alt="" /></p> <p><strong>Example 2:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2021/02/18/btree.jpg" alt="" /></p> <p><strong>Input:</strong> nums = [1,3]</p> <p><strong>Output:</strong> [3,1]</p> <p><strong>Explanation:</strong> [1,3] and [3,1] are both a height-balanced BSTs.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= nums.length <= 10<sup>4</sup></code></li> <li><code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code></li> <li><code>nums</code> is sorted in a <strong>strictly increasing</strong> order.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • sortedArrayToBST

      public TreeNode sortedArrayToBST(int[] num)