Day 23: BST Level-Order Traversal

  • + 1 comment
    def levelOrder(self,root):
        #Write your code here
        queue = [root]
    
        while queue:
            node = queue.pop(0)  # Pop from the front
    
            print(f"{node.data}", end=" ")
    
            for new in [node.left, node.right]:
                if new:
                    queue.append(new)