177.Convert Sorted Array to Binary Search Tree With Minimal Height
1.Description(Easy)
Given a sorted (increasing order) array, Convert it to create a binary tree with minimal height.
Notice
There may exist multiple valid solutions, return any of them.
Example
Given[1,2,3,4,5,6,7]
, return
2.Code
解决方法是选中点构造根节点,然后递归的构造左子树和右子树。
If we build BST from array, we can build it from top to bottom, like
choose the middle one as root,
build left sub BST via left part array
build right sub BST via right part array
do this recursively.
Last updated