Skip to content

Commit

Permalink
이슈 #123에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 19, 2024
1 parent c68c6e1 commit 4fadd99
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions LeetCode/Keys_and_Rooms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution {
public:
bool canVisitAllRooms(vector<vector<int>>& rooms) {
int n = rooms.size();
vector<bool> visited(n, false);
stack<int> s;
s.push(0);
visited[0] = true;

while (!s.empty()) {
int curr = s.top();
s.pop();
for (int key : rooms[curr]) {
if (!visited[key]) {
visited[key] = true;
s.push(key);
}
}
}

for (bool v : visited) {
if (!v) return false;
}

return true;
}
};

0 comments on commit 4fadd99

Please sign in to comment.