Skip to content

Instantly share code, notes, and snippets.

@VXU1230
Last active August 10, 2021 22:48
Show Gist options
  • Save VXU1230/ffbf69992ab21a6f2712f3329c3b18a6 to your computer and use it in GitHub Desktop.
Save VXU1230/ffbf69992ab21a6f2712f3329c3b18a6 to your computer and use it in GitHub Desktop.
class Node:
def __init__(self, val=None):
self.val = val
self.left = None
self.right = None
def get_root():
values = iter([1, 6, 4, 7, None, None, 9, 8, None, None,
10, None, None, 5, None, None, 2, 3, None, None, 11, None, None])
def tree_recur(itr):
val = next(itr)
if val is not None:
node = Node(val)
node.left = tree_recur(itr)
node.right = tree_recur(itr)
return node
return tree_recur(values)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment