deno.land / x / masx200_leetcode_test@10.6.5 / find-if-path-exists-in-graph / index.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { UnionFind } from "../largest-component-size-by-common-factor/UnionFind.ts";
export default function validPath( n: number, edges: number[][], source: number, destination: number,): boolean { if (source === destination) return true; if (edges.length === 0) return false; const nodes = new Set(Array(n).keys()); if (!nodes.has(destination) || !nodes.has(source)) return false; const uf = new UnionFind();
for (const [a, b] of edges) { uf.union(a, b); } return uf.find(destination) === uf.find(source);}
masx200_leetcode_test

Version Info

Tagged at
a year ago