java.lang.Object
g0101_0200.s0109_convert_sorted_list_to_binary_search_tree.Solution

public class Solution extends Object
109 - Convert Sorted List to Binary Search Tree.<p>Medium</p> <p>Given the <code>head</code> of a singly linked list where elements are <strong>sorted in ascending order</strong> , convert it to a height balanced BST.</p> <p>For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of <em>every</em> node never differ by more than 1.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/08/17/linked.jpg" alt="" /></p> <p><strong>Input:</strong> head = [-10,-3,0,5,9]</p> <p><strong>Output:</strong> [0,-3,9,-10,null,5]</p> <p><strong>Explanation:</strong> One possible answer is [0,-3,9,-10,null,5], which represents the shown height balanced BST.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> head = []</p> <p><strong>Output:</strong> []</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> head = [0]</p> <p><strong>Output:</strong> [0]</p> <p><strong>Example 4:</strong></p> <p><strong>Input:</strong> head = [1,3]</p> <p><strong>Output:</strong> [3,1]</p> <p><strong>Constraints:</strong></p> <ul> <li>The number of nodes in <code>head</code> is in the range <code>[0, 2 * 10<sup>4</sup>]</code>.</li> <li><code>-10<sup>5</sup> <= Node.val <= 10<sup>5</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details