Skip to content

Commit d50c90c

Browse files
committed
Time: 8 ms (88.34%), Space: 10.6 MB (36.10%) - LeetHub
1 parent 3ec5716 commit d50c90c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

keys-and-rooms/keys-and-rooms.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution {
2+
public:
3+
void dfs(int x, vector<vector<int>>& adj, vector<int>& vis){
4+
vis[x] = 1;
5+
for(auto v: adj[x]){
6+
if(!vis[v])
7+
dfs(v, adj, vis);
8+
}
9+
}
10+
11+
bool canVisitAllRooms(vector<vector<int>>& rooms) {
12+
int n = rooms.size();
13+
vector<int> vis(n,0);
14+
dfs(0, rooms, vis);
15+
16+
for(int i = 0; i < n; i++){
17+
if(!vis[i])
18+
return false;
19+
}
20+
21+
return true;
22+
}
23+
};

0 commit comments

Comments
 (0)