我试图编写 BFS 代码,但我对这个错误一无所知。为什么我不能简单地使用visited[i][j]==1 ?
int numIslands(vector<vector<char>>& grid)
{
int n = grid.size();
int m = grid[0].size();
vector<vector<int>> vis
for (int i = 0; i < n; i++)
{
vector<int>v;
for (int j = 0; j < m; j++)
{
v.push_back(0);
}
vis.push_back(v);
}
int count = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
if ((vis[i][j] == 0) && (grid[i][j] == '1'))
{
bfs(grid, vis, i, j);
count++;
}
}
}
return count;
}
};
字符 22:错误:'operator==' 不匹配(操作数类型为 '__gnu_cxx::__alloc_traits >, std::vector >::value_type' {aka 'std::vector'} 和 'int') if(( vis[i][j]==0)&&(grid[i][j]=='1'))