Hello everybody,
I hope the test went well for everybody, because it didn't go well for me. I studied the night before the test, hence I didn't have a strong understanding of the material. After looking at the test again I realized that almost everything on the test was explicitly covered.... I'm especially disappointed that I didn't get the 'removing the leaves from a tree' question. This was probably the simplest question on the test, yet I tried solving it by doing a bunch of unnecessary operations at the leaf node, when I could simply, just returned None. I guess I didn't really understand what the question was asking for... Here's the actual solution from the course website:
Code:
def remove_leaves(t: 'BTNode') -> 'BTNode':
if not t or (not t.left and not t.right):
return None # no nodes, or root is leaf
t.left = remove_leaves(t.left)
t.right = remove_leaves(t.right)
return t
No comments:
Post a Comment