From a05eaed14ded0a2bf2faceb91cb8a502a68d5054 Mon Sep 17 00:00:00 2001 From: Huma Hameed Date: Wed, 18 Jan 2023 16:26:34 -0500 Subject: [PATCH] passing all tests --- binary_search_trees/array_to_bst.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/binary_search_trees/array_to_bst.py b/binary_search_trees/array_to_bst.py index f69cc42..04103d6 100644 --- a/binary_search_trees/array_to_bst.py +++ b/binary_search_trees/array_to_bst.py @@ -10,4 +10,13 @@ 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 not arr: + return None + + half = (len(arr)) // 2 + current = TreeNode(arr[half]) + + current.left = arr_to_bst(arr[:half]) + current.right = arr_to_bst(arr[half+1:]) + + return current \ No newline at end of file