108. Convert Sorted Array to Binary Search Tree

Easy

Problem:

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

https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree/arrow-up-right

Solution:

To create a BST, you just need to keep breaking down a sorted array using binary search. Obviously, it won't work if the array isn't sorted. This is because binary search is an algorithm that can find any value in Olog(n)Olog(n) time when used on a sorted array.

Last updated