# My code does not pass!!!

• ``````int **vis;
void dfs(char **a,int i,int j,int r,int c)
{
vis[i][j]=1;
a[i][j]='1';
if(i-1>=0 && a[i-1][j]=='O' && vis[i-1][j]==0)
dfs(a,i-1,j,r,c);
if(j-1>=0 && a[i][j-1]=='O' && vis[i][j-1]==0)
dfs(a,i,j-1,r,c);
if(i+1<r && a[i+1][j]=='O' && vis[i+1][j]==0)
dfs(a,i+1,j,r,c);
if(j+1<c && a[i][j+1]=='O' && vis[i][j+1]==0)
dfs(a,i,j+1,r,c);
}
void solve(char** board, int rows, int cols)
{
int i,j;
vis=(int **)malloc(sizeof(int **)*rows);
for(i=0;i<rows;i++)
{
vis[i]=(int *)malloc(sizeof(int)*cols);
}
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
vis[i][j]=0;
}
}
for(i=0;i<rows;i++)
{
if(board[i][0]=='O' && vis[i][0]==0)
{
dfs(board,i,0,rows,cols);
}
if(board[i][cols-1]=='O' && vis[i][cols-1]==0)
{
dfs(board,i,cols-1,rows,cols);
}
}
for(j=0;j<cols;j++)
{
if(board[0][j]=='O' && vis[0][j]==0)
{
dfs(board,0,j,rows,cols);
}
if(board[rows-1][j]=='O' && vis[rows-1][j]==0)
{
dfs(board,rows-1,j,rows,cols);
}
}
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if(board[i][j]=='O')
board[i][j]='X';
}
}
for(i=0;i<rows;i++)
{
for(j=0;j<cols;j++)
{
if(board[i][j]=='1')
board[i][j]='O';
}
}
}``````

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.