Skip to content

Commit 430012d

Browse files
committed
CTCI 4.2
1 parent e4821e1 commit 430012d

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

minimal_tree.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# CTCI #4.2
2+
3+
def minimal_tree(nums):
4+
5+
root_idx = len(nums)//2
6+
7+
root = BinTree(nums[root_idx])
8+
9+
root.left = minimal_tree(nums[:root_idx-1])
10+
root.right = minimal_tree(nums[root_idx+1:])
11+
12+
return root
13+

0 commit comments

Comments
 (0)