less than 1 minute read

Given a sorted list nums of size n, construct a binary search tree by

  • Taking nums[k] as the root where k = floor(n / 2).
  • Recursively constructing the left subtree using the list nums[:k]
  • Recursively constructing the right subtree using the list nums[k + 1:]

Constraints

  • 0 ≤ n ≤ 100,000

https://binarysearch.com/problems/List-to-Binary-Search-Tree

Examples

Example 1

Input

  • nums = [0, 1, 2, 3, 4]

Output

  • answer =

Solution

Leave a comment