List to Binary Search Tree
Given a sorted list nums of size n, construct a binary search tree by
- Taking
nums[k]as the root wherek = 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 =
Leave a comment