Skip to content

Instantly share code, notes, and snippets.

@leejh3224
Created April 17, 2021 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leejh3224/64775bdd2e09ce9506fc72adcbdd5618 to your computer and use it in GitHub Desktop.
Save leejh3224/64775bdd2e09ce9506fc72adcbdd5618 to your computer and use it in GitHub Desktop.
def level_bfs():
queue = []
queue.append(root)
while queue:
size = len(queue)
node = queue.pop(0)
while size:
if node.left:
queue.append(node.left)
if node.right:
queue.append(node.right)
# end of each level
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment