From 74f033c72cd692812c74fe06540c902b1bbc31c6 Mon Sep 17 00:00:00 2001 From: Alexa Coffman Date: Thu, 12 Jan 2023 14:55:35 -0800 Subject: [PATCH] Complete arr_to_bst method git push --- 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..9511896 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 + + mid = len(arr) // 2 + + return TreeNode( + arr[mid], + arr_to_bst(arr[:mid]), + arr_to_bst(arr[mid + 1:]) + )