• ``````struct pinfo{
char * loc;
int x;
int y;
pinfo(char * loc, int x, int y):loc(loc),x(x),y(y){}
};
class Solution {
public:
void solve(vector<vector<char>> &board) {

vector<set<char *>> vec;
set<char *> dealed;
vector<char *> wait;

for(int j=0; j<board.size(); j++)
for(int i=0; i<board[0].size(); i++)
{
if(board[j][i]=='o' && dealed.find(&board[j][i]) == dealed.end())
{
if(bfs(board, dealed, wait, i, j))
{
for(vector<char *>::iterator ite = wait.begin(); ite != wait.end(); ite++)
{
**ite = 'x';
}
}
}
}
}
private:
bool bfs(vector<vector<char>> &board, set<char *> &dealed, vector<char *> &wait, int i, int j)
{
bool flag = true;
queue<pinfo> que;
wait.push_back(&board[j][i]);
dealed.insert(&board[j][i]);
pinfo p(&board[j][i],j,i);
que.push(p);
if(i == 0 || j == 0 || i+1 == board[0].size() || j+1 == board.size())
{
flag = false;
}

while(que.size()>0)
{
int x = que.front().x;
int y = que.front().y;

if(x - 1 >= 0 && board[y][x-1] == 'o'  && dealed.find(&board[y][x-1]) == dealed.end())
{
if(x-1 == 0)flag = false;
pinfo ptmp(&board[y][x-1], x-1, y);
que.push(ptmp);
wait.push_back(&board[y][x-1]);
dealed.insert(&board[y][x-1]);
}
if(y - 1 >= 0 && board[y-1][x] == 'o'  && dealed.find(&board[y-1][x]) == dealed.end())
{
if(y - 1 == 0)flag = false;
pinfo ptmp(&board[y-1][x], x, y-1);
que.push(ptmp);
wait.push_back(&board[y-1][x]);
dealed.insert(&board[y-1][x]);
}
if(x + 1 < board[0].size() && board[y][x+1] == 'o'  && dealed.find(&board[y][x+1]) == dealed.end())
{
if(x + 1 == board[0].size())flag = false;
pinfo ptmp(&board[y][x+1], x+1, y);
que.push(ptmp);
wait.push_back(&board[y][x+1]);
dealed.insert(&board[y][x+1]);
}
if(y + 1 < board.size() && board[y+1][x] == 'o' && dealed.find(&board[y+1][x]) == dealed.end())
{
if(y + 1 == board.size())flag = false;
pinfo ptmp(&board[y+1][x], x, y+1);
que.push(ptmp);
wait.push_back(&board[y+1][x]);
dealed.insert(&board[y+1][x]);
}
que.pop();
}
return flag;
}
};
``````

After Sub: