Untitled

mail@pastecode.io avatar
unknown
c_cpp
a year ago
373 B
1
Indexable
int countHouses(vector<vector<int>> grid)
{
    vector<vector<bool>> visited(rows, vector<bool>(cols, false));
    int count = 0;

    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            if (grid[i][j] && !visited[i][j]) {
                DFS(i, j, grid, visited);
                count++;
            }
        }
    }
    return count;
}