Original title URL: https://www.lintcode.com/problem/convert-sorted-array-to-binary-search-tree-with-minimal-height/description
Describe
Give a sorted array (from small to large) and convert it to a binary tree with the smallest height.
There may exist multiple valid solutions and return any of them.
Have you ever encountered this problem in a real interview? is a sample
Give the array [1,2,3,4,5,6,7] , return
4 / 2 6 / \ / 1 3 5 7
tagged two fork tree recursive cracking the Coding interview
idea : two fork tree problem daily ... The first thing to think is to iterate through the array, a node of one node to build a two-tree, later, of course, is not going to do it ... After looking at the other people's answers on the internet, I got the idea, wrote out the code, summed up:
Create two fork tree should first establish the root node , and then mount the left and right children. Instead of first creating the kids around and then
177 converting a sorted array to a two-prong search tree with a minimum height