Skip to content

Instantly share code, notes, and snippets.

@liondancer
Created January 2, 2017 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liondancer/a484978a1ad110ee05286f20ec29d9ae to your computer and use it in GitHub Desktop.
Save liondancer/a484978a1ad110ee05286f20ec29d9ae to your computer and use it in GitHub Desktop.
def sortedArrayToBST(nums):
if nums:
mid = len(nums) / 2
node = TreeNode(nums[mid])
node.left = sortedArrayToBST(nums[:mid])
node.right = sortedArrayToBST(nums[mid + 1:])
return node
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment