1 Star 0 Fork 0

杨杰 / 力扣第841题

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
力扣第841题.txt 825 Bytes
一键复制 编辑 原始数据 按行查看 历史
杨杰 提交于 2023-12-11 18:00 . 力扣第841题.txt
class Solution {
public:
bool canVisitAllRooms(vector<vector<int>>& rooms) {
int n=rooms.size();
queue<int> q;
vector<bool> ret(n);
ret[0]=true;
for(int i=0;i<rooms[0].size();i++)
{
if(ret[rooms[0][i]]==false)
{
q.push(rooms[0][i]);
}
}
while(!q.empty())
{
int i=q.front();
q.pop();
int n=rooms[i].size();
ret[i]=true;
for(int j=0;j<n;j++)
{
if(ret[rooms[i][j]]==false)
{
q.push(rooms[i][j]);
}
}
}
for(int i=0;i<n;i++)
{
if(ret[i]==false)
return false;
}
return true;
}
};
C++
1
https://gitee.com/yang-jieCyuyan/deduction-question-841.git
git@gitee.com:yang-jieCyuyan/deduction-question-841.git
yang-jieCyuyan
deduction-question-841
力扣第841题
master

搜索帮助