Very Easy approach in C++


#1

void visit(vector &A, int row, int col, int n, int m)
{
if(row<0 || row>=n || col<0 || col>=m || A[row][col]==‘O’) return;
A[row][col]=‘O’;
visit(A, row+1,col,n,m);
visit(A, row-1,col,n,m);
visit(A, row,col-1,n,m);
visit(A, row,col+1,n,m);
}

int Solution::black(vector &A)
{
int n = A.size();
int m = A[0].size();
int count = 0;

for(int i=0;i<n;i++)
{
    for(int j=0;j<m;j++)
    {
        if(A[i][j]=='X')
        {
            visit(A,i,j,n,m);
            count++;
        }
    }
}
return count;

}