Easy
思路其实很简单,明显的递归题
以上,尝试写一下代码,AC!
python3
class Solution:
def build(self, nums):
if len(nums) is 0:
return None
mid = len(nums) // 2
m = nums[mid]
left = nums[:mid]
right = nums[mid+1:]
node = TreeNode(m)
node.left = self.build(left)
node.right = self.build(right)
return node
def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
return self.build(nums)