• ``````class Solution {
public:
int help(vector<vector<char>> &board,vector<vector<int>> &vis,vector<int> &xx,vector<int> &yy,int x,int y)
{
int i,j,m,n;
m=board.size();
n=board[0].size();

if(x<0 || x>=m || y<0 || y>=n)
return 0;

if(!vis[x][y] && board[x][y]=='O')
{
//  cout<<x<<" "<<y<<endl;
if(x==0 || x==m-1 || y==0 || y==n-1)
return 1;

vis[x][y]=1;

xx.push_back(x);
yy.push_back(y);

return  help(board,vis,xx,yy,x+1,y) ||  help(board,vis,xx,yy,x-1,y) ||  help(board,vis,xx,yy,x,y-1) ||  help(board,vis,xx,yy,x,y+1);
}
return 0;

}
void solve(vector<vector<char>>& board) {

int i,j,m,n;
m=board.size();
if(m==0)
return ;
n=board[0].size();
if(n==0)
return ;
vector<vector<int>> vis(m,vector<int> (n,0));

for(i=1;i<m-1;i++)
{
for(j=1;j<n-1;j++)
{
vector<int> xx;
vector<int> yy;
//cout<<i<<" "<<j<<endl;
if(board[i][j]=='O' && !vis[i][j])
{
// cout<<i<<" "<<j<<endl;
if(!help(board,vis,xx,yy,i,j))
{
//    cout<<endl;
for(int k=0;k<xx.size();k++)
{
//cout<<xx[k]<<endl;
board[xx[k]][yy[k]]='X';
}
}
}
}
}

}
};``````

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