更多python分类刷题题解代码:请参考github,博客, 知乎
https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/
# 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:
def helper(nums):
if not nums: return
l = len(nums)
mid = l // 2
node = TreeNode(nums[mid])
node.left = helper(nums[:mid])
node.right = helper(nums[mid+1:])
return node
return helper(nums)
更多python分类刷题题解代码:请参考github,博客, 知乎
本文地址:https://blog.csdn.net/lxztju/article/details/107134834
如对本文有疑问, 点击进行留言回复!!
Python3以GitHub为例来实现模拟登录和爬取的实例讲解
网友评论