DFS BFS?
有向图?
class Solution {
void dfs( List<List<Integer>> rooms , int room , boolean[] finish){
if( finish[ room ] ) return;
else finish[ room ] = true;
List<Integer> cur = rooms.get(room);
for( int i = 0 ; i < cur.size() ; i ++ ){
dfs( rooms , cur.get( i ) , finish );
}
}
public boolean canVisitAllRooms(List<List<Integer>> rooms) {
int n = rooms.size();
boolean[] finish = new boolean[n];
// finish[ 0 ] = true;
dfs( rooms , 0 , finish );
for( boolean i : finish )
if( !i )
return false;
return true;
}
}