描述:递归
代码:
1 class Solution: 2 # @param num, a list of integers 3 # @return a tree node 4 def sortedArrayToBST(self, num): 5 if len(num) == 0: 6 return None 7 8 mid_index = len(num) / 2 9 10 tmp_tree = TreeNode(num[mid_index]) 11 tmp_tree.left = self.sortedArrayToBST(num[:mid_index]) 12 tmp_tree.right = self.sortedArrayToBST(num[mid_index + 1:]) 13 14 return tmp_tree