From 535885c671810b371e390dcb3f45b432aa64e9de Mon Sep 17 00:00:00 2001 From: Elaine Smith Date: Thu, 8 Dec 2022 11:02:51 -0800 Subject: [PATCH] Problem Solved --- binary_search_trees/array_to_bst.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/binary_search_trees/array_to_bst.py b/binary_search_trees/array_to_bst.py index f69cc42..fea240d 100644 --- a/binary_search_trees/array_to_bst.py +++ b/binary_search_trees/array_to_bst.py @@ -10,4 +10,12 @@ def arr_to_bst(arr): Balanced Binary Search Tree using the elements in the array. Return the root of the Binary Search Tree. """ - pass \ No newline at end of file + # base case + if not arr: + return None + + mid = len(arr)//2 + + # recursion + return TreeNode(arr[mid], arr_to_bst(arr[:mid]), arr_to_bst(arr[mid + 1:])) + \ No newline at end of file