这可以用建立邻接表的形式来做,用一个hashmap存放每个结点能指向哪些结点,然后将start放入队列,找出对应key值中能到达且没访问过的结点,放入队列并把相应布尔数组的值置为true,若队列空了则没有通路。
代码:class Solution {
public boolean findWhetherExistsPath(int n, int[][] graph, int start, int target) {
boolean[] b=new boolean[n];
HashMap> hhash=new HashMap>();
Queue q=new linkedList();
for(int i=0;i



