标签:
108 Convert Sorted Array to Binary Search Tree
递归解法还是非常直观的
class Solution: # @param {integer[]} nums # @return {TreeNode} def sortedArrayToBST(self, nums): return self.help(nums, 0, len(nums) - 1) def help(self, nums, left, right): if left == right: return TreeNode(nums[left]) if left > right: return None mid = (left + right) / 2 node = TreeNode(nums[mid]) node.left = self.help(nums, left, mid - 1) node.right = self.help(nums, mid + 1, right) return node
108 Convert Sorted Array to Binary Search Tree
标签:
原文地址:http://www.cnblogs.com/dapanshe/p/4669180.html