my accepted python solution


  • 0
    A
    class Solution(object):
        def sortedArrayToBST(self, nums):
            first = 0
            last = len(nums) - 1
            mid = len(nums) // 2
            
            if first > last:
                return
            
            root = TreeNode(nums[mid])
            
            root.left = self.sortedArrayToBST(nums[:mid])
            root.right = self.sortedArrayToBST(nums[mid+1:])
    
            return root
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.