Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.
Input: nums = [-10,-3,0,5,9]
Output: [0,-3,9,-10,null,5]
Explanation: [0,-10,5,null,-3,null,9] is also accepted
Input: nums = [1,3]
Output: [3,1]
Explanation: [1,null,3] and [3,1] are both height-balanced BSTs.
- 1 <= nums.length <= 10^4
- 10^4 <= nums[i] <= 10^4
- nums is sorted in a strictly increasing order.
LeetCode: Convert Sorted Array to Binary Search Tree
Let's start to use this project.
There is a python file with the code and a Jupyter Notebook to visualize the code execution in your browser.
Python 3 must be installed. Install requirements using requirements.txt file
pip3 install -r requirements.txt
To execute the project open the terminal and go to the project folder. Then execute it with python:
python3 array_to_BST.py
You can also use Jupyter Notebook to execute it in your browser or text editor directly.