Categories
Binary Tree Breadth First Search

Level Order Tree Traversal

function levelOrder(root) {

let queue = [root], result = [];
function process(node) {
result.push(node.val);
}

while (queue.length) {
const node = queue.pop();
process(node);
if (node.left) queue.unshift(node.left);
if (node.right) queue.unshift(node.right);
}

return result; //?
}

Leave a Reply

Your email address will not be published. Required fields are marked *