Skip to content

Instantly share code, notes, and snippets.

@pirate-kiiiing
Last active October 8, 2022 07:13
def levelorder(root: TreeNode) -> None:
if not root: return
q = deque([root])
while q:
size = len(q)
for i in range(size):
node = q.popleft()
print(str(node.val), end = " ")
if node.left:
q.append(node.left)
if node.right:
q.append(node.right)
print()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment