MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / bfs

Function bfs

javascript/0226-invert-binary-tree.js:39–53  ·  view source on GitHub ↗
(queue)

Source from the content-addressed store, hash-verified

37};
38
39const bfs = (queue) => {
40 while (queue.length) {
41 for (let i = queue.length - 1; 0 <= i; i--) {
42 const node = queue.shift();
43 const left = node.right;
44 const right = node.left;
45
46 node.left = left;
47 node.right = right;
48
49 if (node.left) queue.push(node.left);
50 if (node.right) queue.push(node.right);
51 }
52 }
53};

Callers 1

invertTreeFunction · 0.70

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected