标签:style blog color io 代码 div ar log
描述:递归
代码:
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
#Leet Code# Convert Sorted Array to Binary Search Tree,布布扣,bubuko.com
#Leet Code# Convert Sorted Array to Binary Search Tree
标签:style blog color io 代码 div ar log
原文地址:http://www.cnblogs.com/mess4u/p/3875364.html