leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0841.cpp (504B)


0 class Solution {
1 public:
2 bool canVisitAllRooms(vector<vector<int>> &rooms) {
3 unordered_set<int> us;
4 queue<int> q;
6 q.push(0);
7 us.insert(0);
8 while (!q.empty()) {
9 int room = q.front();
10 q.pop();
11 for (int key : rooms[room]) {
12 if (!us.count(key)) {
13 us.insert(key);
14 q.push(key);
15 }
16 }
17 }
18 return us.size() == rooms.size();
19 }
20 };