We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def levelOrder(root):
if root is None:
return
q = [root]
while(len(q) > 0):
n = q.pop(0)
print(n.info, end = ' ')
if n.left:
q.append(n.left)
if n.right:
q.append(n.right)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Level Order Traversal
You are viewing a single comment's thread. Return to all comments →
def levelOrder(root): if root is None: return q = [root] while(len(q) > 0): n = q.pop(0) print(n.info, end = ' ') if n.left: q.append(n.left) if n.right: q.append(n.right)