Skip to content

Commit 5df80e5

Browse files
authored
Add files via upload
1 parent b48094f commit 5df80e5

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Node {
2+
constructor(value, neighbors = []) {
3+
this.value = value;
4+
this.neighbors = neighbors;
5+
}
6+
}
7+
8+
function bfs(start, target) {
9+
const queue = [start];
10+
const visited = new Set();
11+
12+
while (queue.length) {
13+
const node = queue.shift();
14+
if (node.value === target) return true;
15+
if (visited.has(node)) continue;
16+
visited.add(node);
17+
18+
queue.push(...node.neighbors);
19+
}
20+
21+
return false;
22+
}
23+

0 commit comments

Comments
 (0)