From 5383ebd41e35aefe134d67bd5b42d5c12f6d2738 Mon Sep 17 00:00:00 2001 From: verasazonova Date: Mon, 26 Dec 2022 15:50:09 -0800 Subject: [PATCH] VeraSa C17 --- 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..9571234 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 + if not arr: + return None + + middle = (len(arr)) // 2 + + root = TreeNode(arr[middle]) + root.left = arr_to_bst(arr[:middle]) + root.right = arr_to_bst(arr[middle + 1:]) + return root \ No newline at end of file