(queue)
| 54 | }; |
| 55 | |
| 56 | const 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 | |
| 71 | const isSameNode = (p, q) => { |
| 72 | const isBaseCase = !(p || q); |
no test coverage detected