Convert Sorted Array to Binary Search Tree (C# and Python3)

Given an integer array nums where the elements are sorted in ascending order, convert it to a height-balanced binary search tree.

height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one.

Solution

Step 1: select a root (the middle)

Step 2: create subarrays at the left and the right of the array

Step 3: Recursive DFS

C#

Python3

Don’t miss these tips!

We don’t spam! Read our privacy policy for more info.