Karleb
Posted on
#1971. Find if Path Exists in Graph
functionhasPath(graph,src,dest,visited){visited[src]=true;if(src===dest)returntrue;for(letneighborofgraph[src]){if(!visited[neighbor]){if(hasPath(graph,neighbor,dest,visited))returntrue;}}returnfalse;}functionvalidPath(n,edges,start,end){constgraph=Array.from({length:n},()=>[]);for(let[u,v]ofedges){graph[u].push(v);graph[v].push(u);}constvisited=Array(n).fill(false);returnhasPath(graph,start,end,visited);}
Top comments(0)
Subscribe
For further actions, you may consider blocking this person and/orreporting abuse