From 481f0b6b48e6aceceaacf4e1c785850b74f84279 Mon Sep 17 00:00:00 2001 From: Victoria Shade Date: Thu, 19 Jan 2023 05:01:44 -0800 Subject: [PATCH] solution w/ tests passing --- binary_search_trees/array_to_bst.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/binary_search_trees/array_to_bst.py b/binary_search_trees/array_to_bst.py index f69cc42..faaee61 100644 --- a/binary_search_trees/array_to_bst.py +++ b/binary_search_trees/array_to_bst.py @@ -10,4 +10,9 @@ 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 + if len(arr) == 0: + return + + total_lenght = len(arr) + middle_node = total_lenght // 2 + return TreeNode(arr[middle_node], arr_to_bst(arr[:middle_node]), arr_to_bst(arr[middle_node+1:])) \ No newline at end of file