aboutsummaryrefslogtreecommitdiff
path: root/other/keys_and_rooms.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'other/keys_and_rooms.cpp')
-rw-r--r--other/keys_and_rooms.cpp32
1 files changed, 0 insertions, 32 deletions
diff --git a/other/keys_and_rooms.cpp b/other/keys_and_rooms.cpp
deleted file mode 100644
index 59308ef..0000000
--- a/other/keys_and_rooms.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include "leetcode.h"
-
-class Solution {
-public:
- bool canVisitAllRooms(vvd & rooms) {
- stack<int> dfs;
- dfs.push(0);
- unordered_set<int> seen = {0};
- while (!dfs.empty()) {
- int i = dfs.top();
- dfs.pop();
- for (int j : rooms[i]) {
- if (seen.count(j) == 0) {
- dfs.push(j);
- seen.insert(j);
- if (rooms.size() == seen.size())
- return true;
- }
- }
- }
- return rooms.size() == seen.size();
- }
-};
-
-int main() {
- Solution obj;
- vvd rooms = {{1}, {2}, {3}, {}};
- if (obj.canVisitAllRooms(rooms))
- cout << "true";
- else
- cout << "false";
-}