面试题 04.02
Given a sorted (increasing order) array with unique integer elements, write an algorithm to create a binary search tree with minimal height.
Example:
Given sorted array: [-10,-3,0,5,9],
One possible answer is: [0,-3,9,-10,null,5],which represents the following tree:
Solutions
binary search tree
Recursively build the root node with the middle element and link subtrees of two parts as the child nodes.
Last updated
Was this helpful?