본문 바로가기
LeetCode/Top Interview Q. - Easy

LeetCode. Convert Sorted Array to Binary Search Tree [Trees]

by 벤진[Benzene] 2020. 6. 7.

Problem:

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.

For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

 

Example:

-Summary-

Solve by recursive function call

1. First, find a root first by finding the midpoint of the given integer array.

2. Any numbers on the left should be less than the midpoint number.

   Any numbers on the right should be larger than the midpoint number.

3. We keep recursively add the node by find mid and add left and right sub-tree.

모든 문제에 대한 저작권은 LeetCode 회사에 있습니다. [Copyright © 2020 LeetCode]

댓글