构建有向连通图,然后进行BFS,如果能到达target就返回true 否则返回false
代码class Solution {
public boolean findWhetherExistsPath(int n, int[][] graph, int start, int target) {
Map> map = new HashMap<>();
for (int i=0;i set = new HashSet<>();
set.add(go[1]);
map.put(go[0],set);
}else {
HashSet set = map.get(go[0]);
set.add(go[1]);
}
}
boolean[] visited = new boolean[n];
linkedList queue = new linkedList<>();
queue.add(start);
visited[start] = true;
while (!queue.isEmpty()){
int size = queue.size();
for (int i=0;i set = map.get(first);
for (int key : set){
if (!visited[key]){
queue.add(key);
visited[key] = true;
}
}
}
}
}
return false;
}
}



