题目描述:
解题过程:
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def sortedArrayToBST(self, nums: List[int]) -> TreeNode:
if not nums:
return None
mid_index=len(nums)//2
pNode=TreeNode(nums[mid_index])
pNode.left=self.sortedArrayToBST(nums[:mid_index])
pNode.right=self.sortedArrayToBST(nums[mid_index+1:])
return pNode
题目暂未看懂,我需要读一遍算法橙书,但这学期还有更重要的事情,故橙书的阅读放到6.15之后进行。