Consider:
for (auto i = 0; i < g.size(); ++i)
for (auto j = 0; j < g.size(); ++j) if (g[i][j] == 0) dfs(g, i, j), ++regions;
return regions;
I don't like one line code. What does the code execute in the if()
?
I am confused by the "," sign.
Usually I would write it as:
for (auto i = 0; i < g.size(); ++i)
{
for (auto j = 0; j < g.size(); ++j)
{
if (g[i][j] == 0)
{
dfs(g, i, j)
}
,++regions; // I am not sure what to do here. Inside the "if" scope??
}
}
return regions;