177 converting a sorted array to a two-prong search tree with a minimum height

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.