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

Function bfs

javascript/0100-same-tree.js:56–69  ·  view source on GitHub ↗
(queue)

Source from the content-addressed store, hash-verified

54};
55
56const bfs = (queue) => {
57 while (queue.length) {
58 for (let i = queue.length - 1; 0 <= i; i--) {
59 const [p, q] = queue.shift();
60
61 if (!isSame(p, q)) return false;
62
63 if (p.left) queue.push([p.left, q.left]);
64 if (p.right) queue.push([p.right, q.right]);
65 }
66 }
67
68 return true;
69};
70
71const isSameNode = (p, q) => {
72 const isBaseCase = !(p || q);

Callers 1

isSameTreeFunction · 0.70

Calls 2

isSameFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected