Iam_Sandeep

Convert Sorted array to BST

Apr 18th, 2022
1,051
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.32 KB | None | 0 0
  1. class Solution(object):
  2.     def sortedArrayToBST(self, arr):
  3.         def convert(arr,s,e):
  4.             if s>e:return None
  5.             m=(s+e)>>1
  6.             t=TreeNode(arr[m])
  7.             t.left=convert(arr,s,m-1)
  8.             t.right=convert(arr,m+1,e)
  9.             return t
  10.         return convert(arr,0,len(arr)-1)
Advertisement
Add Comment
Please, Sign In to add comment